Example #1
0
    def setUp(self):
        super().setUp()

        self.feed1 = RSSFeedRule().feed1

        RSSFeedRegistration.find_or_create(
            zeeguu_core.db.session, self.user, self.feed1
        )
Example #2
0
def get_feeds_being_followed():
    """
    A user might be following multiple feeds at once.
    This endpoint returns them as a list.

    :return: a json list with feeds for which the user is registered;
     every feed in this list is a dictionary with the following info:
                id = unique id of the feed; uniquely identifies feed in other endpoints
                title = <unicode string>
                url = ...
                language = ...
                image_url = ...
    """
    registrations = RSSFeedRegistration.feeds_for_user(flask.g.user)
    feed_list = []
    for reg in registrations:
        try:
            feed_list.append(reg.rss_feed.as_dictionary())
        except Exception as e:
            from sentry_sdk import capture_exception

            capture_exception(e)
            zeeguu_core.log(str(e))

    return json_result(feed_list)
Example #3
0
def start_following_feed_with_id():
    """
    :param: feed_id -- the id of the feed to be followed.
    Start following the feed with the given id

    :return: "OK" in case of success
    """
    if request.form.get("source_id", ""):
        feed_id = int(request.form.get("source_id", ""))
    else:
        feed_id = int(request.form.get("feed_id", ""))

    feed_object = RSSFeed.find_by_id(feed_id)
    RSSFeedRegistration.find_or_create(session, flask.g.user, feed_object)

    return "OK"
Example #4
0
def get_non_subscribed_feeds(language_code):
    """
    Get a list of feeds for the given language

    :return:
    """
    feeds = RSSFeedRegistration.non_subscribed_feeds(flask.g.user, language_code)
    feed_data = [feed.as_dictionary() for feed in feeds]
    return json_result(feed_data)
Example #5
0
def stop_following_feed():
    """
    A user can stop following the feed with a given ID
    :return: OK / ERROR
    """

    feed_id = int(request.form.get('source_id', ''))

    try:
        to_delete = RSSFeedRegistration.with_feed_id(feed_id, flask.g.user)
        session.delete(to_delete)
        session.commit()
    except Exception as e:
        return "OOPS. FEED AIN'T THERE IT SEEMS (" + str(e) + ")"

    return "OK"
Example #6
0
def get_non_subscribed_feeds(language_code):
    """
    Get a list of feeds for the given language

    :return:
    """
    feed_data = []
    already_registered = [
        each.rss_feed
        for each in RSSFeedRegistration.feeds_for_user(flask.g.user)
    ]

    all_available_for_language = RSSFeed.find_for_language_id(language_code)

    for feed in all_available_for_language:
        if not (feed in already_registered):
            feed_data.append(feed.as_dictionary())

    return json_result(feed_data)
from zeeguu_core.model import User, UserLanguage, RSSFeedRegistration

session = zeeguu_core.db.session

counter = 0

all_users = User.query.all()

for user in all_users:
    learned_languages = []

    # Grab the learned language and add it to learned_languages
    learned_languages.append(user.learned_language)

    # Go through the user sources
    user_feed_registrations = RSSFeedRegistration.feeds_for_user(user)

    for feed_reg in user_feed_registrations:
        # Try catch is needed because apparently there are NoneType feeds in registrations..
        try:
            feed = feed_reg.rss_feed
            feed_language = feed.language
            if feed_language not in learned_languages:
                learned_languages.append(feed_language)
        except Exception as e:
            print(e)

    for language in learned_languages:
        user_language = UserLanguage.find_or_create(session, user, language)
        user_language.reading_news = True
        session.add(user_language)
Example #8
0
    def setUp(self):
        super().setUp()

        self.feed1 = RSSFeedRule().feed1

        RSSFeedRegistration.find_or_create(zeeguu_core.db.session, self.user, self.feed1)