Beispiel #1
0
    def get_template_values(self):
        subscriptions = get_config().get('subscriptions')
        feeds = Feed.all().order('-date')
        template_values = {
            'feeds': feeds,
            'subscriptions': subscriptions
        }

        return template_values
Beispiel #2
0
    def run(self):
        for subscription in self.config['subscriptions']:
            logging.info("Parsing started for :%s" % subscription['url'])
            # get feed data from subscription
            feed_data = feedparser.parse(subscription['feed_url'])

            # clean it up...
            feed_data = feed_filter.get(feed_data)

            for entry in feed_data.entries:

                # entry becomes a anchestor to entry that stored on
                # database, or returns 0
                entry_on_db = Feed.all().filter("url =", entry.link).get()

                if entry_on_db:

                    # If exists, look for update date,
                    time_difference = entry_on_db.date - entry.date

                    if time_difference.seconds > 0:
                        # It needs to be updated.
                        entry_on_db.title = entry.title
                        entry_on_db.content = entry.summary
                        entry_on_db.date = entry.date
                        entry_on_db.put()
                        logging.info("%s is updated, time difference was %d seconds" % (entry_on_db.url, time_difference.seconds))
                    else:
                        # I now that is not needed but i want that code
                        # easy to read
                        pass
                else:
                    # If not exists , create a new one
                    entry_on_db = Feed(
                        author=subscription['name'],
                        title=entry.title,
                        date=entry.date,
                        content=entry.summary,
                        url=entry.link)
                    # Put it to database ^_^
                    entry_on_db.put()
                    logging.info("%s is added" % entry_on_db.url)