def article_recommendations_for_user(user, count): """ Retrieve :param count articles which are equally distributed over all the feeds to which the :param user is registered to. Fails if no language is selected. :return: """ import zeeguu_core user_languages = UserLanguage.all_reading_for_user(user) if not user_languages: return [] reading_pref_hash = reading_preferences_hash(user) recompute_recommender_cache_if_needed(user, zeeguu_core.db.session) all_articles = ArticlesCache.get_articles_for_hash(reading_pref_hash, count) all_articles = [ each for each in all_articles if (not each.broken and each.published_time) ] all_articles = SortedList(all_articles, lambda x: x.published_time) return [ user_article_info(user, article) for article in reversed(all_articles) ]
def find_articles_for_user(user): """ This method gets all the topic and search subscriptions for a user. It then returns all the articles that are associated with these. :param user: :return: """ user_languages = UserLanguage.all_reading_for_user(user) topic_subscriptions = TopicSubscription.all_for_user(user) search_subscriptions = SearchSubscription.all_for_user(user) subscribed_articles = filter_subscribed_articles(search_subscriptions, topic_subscriptions, user_languages, user) return subscribed_articles
def get_user_articles_sources_languages(user, limit=1000): """ This method is used to get all the user articles for the sources if there are any selected sources for the user, and it otherwise gets all the articles for the current learning languages for the user. :param user: the user for which the articles should be fetched :param limit: the amount of articles for each source or language :return: a list of articles based on the parameters """ user_languages = UserLanguage.all_reading_for_user(user) all_articles = [] for language in user_languages: log(f'Getting articles for {language}') new_articles = language.get_articles(most_recent_first=True) all_articles.extend(new_articles) log(f'Added {len(new_articles)} articles for {language}') return all_articles