def handle_json_notification(self, feed, data): """Handles PuSH notifications in JSON format""" app.logger.info(u'Handling JSON notification for {0}'.format(feed)) if data.get('title'): feed.title = data.get('title') if data.get('description'): feed.description = data.get('description') db.session.add(feed) if data.get('items') is None: app.logger.warning(u'No entries in notification for {0}' .format(feed)) return for item in data.get('items'): try: itemId = item.get('id') except KeyError: itemId = item.get('link') if itemId is None: app.logger.warning(u'Could not get itemId for item {0} in ' 'feed {1}'.format(item, feed)) continue entry = Entry.query.filter_by(guid=itemId).first() if entry is None: entry = Entry(feed=feed) entry.title = item.get('title') entry.guid = itemId try: entry.published = datetime.fromtimestamp(item.get('published')) except Exception: pass try: entry.updated = datetime.fromtimestamp(item.get('updated')) except Exception: pass if item.get('content') is None: entry.content = item.get('summary') else: entry.content = item.get('content') entry.summary = item.get('summary') entry.link = item.get('permalinkUrl') self.add_authors(entry, item.get('actor.displayname')) entry.get_wordcount() app.logger.info(u'Adding entry <{0}>'.format(entry)) self.entries.append(entry) db.session.add(entry) return
def handle_notification(self, feed, data): """Handles PuSH notifications in RSS and Atom format.""" app.logger.info(u'Handling RSS notification for {0}'.format(feed)) if data.feed is not None: if data.feed.get('title'): feed.title = data.feed.get('title') if data.feed.get('subtitle'): feed.description = data.feed.get('subtitle') elif data.feed.get('description'): feed.description = data.feed.get('description') db.session.add(feed) if data.entries is None: app.logger.warning(u'No entries in notification for {0}' .format(feed)) return for item in data.entries: try: itemId = item.get('id') except KeyError: itemId = item.get('link') if itemId is None: app.logger.warning(u'Could not get itemId for item {0} in ' 'feed {1}'.format(item, feed)) continue entry = Entry.query.filter_by(guid=itemId).first() if entry is None: entry = Entry(feed=feed) try: entry.published = datetime.fromtimestamp( mktime(item.get('published_parsed'))) except Exception: pass try: entry.updated = datetime.fromtimestamp( mktime(item.get('updated_parsed'))) except Exception: pass entry.title = item.get('title') entry.guid = itemId entry.link = item.get('link') if item.get('content') is None: entry.content = item.get('summary') else: content = item.get('content')[0] entry.content = content.get('value') entry.summary = item.get('summary') self.add_authors(entry, item.get('author')) entry.get_wordcount() app.logger.info(u'Adding entry <{0}>'.format(entry)) self.entries.append(entry) db.session.add(entry) return