2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
18 from collections
import Counter
21 from django
.conf
import settings
23 from mygpo
.db
.couchdb
.podcast_state
import subscribed_users
, \
24 subscribed_podcast_ids_by_user_id
25 from mygpo
import pubsub
27 logger
= logging
.getLogger(__name__
)
30 def calc_similar_podcasts(podcast
, num
=20):
32 calculates and returns a list of podcasts that seem to be similar
35 Probably an expensive operation
38 users
= subscribed_users(podcast
)
43 user_subscriptions
= subscribed_podcast_ids_by_user_id(user_id
)
44 user_counter
= Counter(user_subscriptions
)
45 podcasts
.update(user_counter
)
47 return podcasts
.most_common(num
)
50 def subscribe_at_hub(podcast
):
51 """ Tries to subscribe to the given podcast at its hub """
56 base_url
= settings
.DEFAULT_BASE_URL
59 logger
.warn('Could not subscribe to podcast {podcast} '
60 'at hub {hub} because DEFAULT_BASE_URL is not '
61 'set.'.format(podcast
=podcast
, hub
=podcast
.hub
))
64 logger
.info('subscribing to {podcast} at {hub}.'.format(podcast
=podcast
,
66 pubsub
.subscribe(podcast
.url
, podcast
.hub
, base_url
)