Mercurial > hg > Feedworm
view backend/arangodb/ArangoBackend.py @ 259:304917762618 default tip
implementation of feed updates
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 12 Mar 2019 02:41:22 +0100 |
parents | f79be01821c4 |
children |
line wrap: on
line source
# -*- coding: utf-8 -*- from argparse import ArgumentParser from ArangoDb import ArangoDb from backend.AbstractBackend import AbstractBackend from Feed import Feed from FeedEntry import FeedEntry from FeedUpdater import FeedUpdater from Preferences import Preferences from pyArango.connection import Connection """ Backend that uses ArangoDB for persistence """ class ArangoBackend(AbstractBackend): def __init__(self): super(ArangoBackend, self).__init__() args = self._parse_arguments() connection = Connection(arangoURL=args.dburl, username=args.user, password=args.password) self.database = ArangoDb(connection[args.dbname]) self.prefs = None def _parse_arguments(self): parser = ArgumentParser() parser.add_argument('--dburl', nargs='?', help='URL of the database', default='http://127.0.0.1:8529') parser.add_argument('--dbname', nargs='?', help='name of the database', default='feedworm') parser.add_argument('--user', nargs='?', help='username for authenticating the database connection', required=True) parser.add_argument('--password', nargs='?', help='password for authenticating the database connection', required=True) return parser.parse_known_args()[0] def preferences(self): if self.prefs is None: self.prefs = Preferences(self.database) return self.prefs def getUnreadFeeds(self): return Feed.get_unread(self.database) def _retrieveEntriesForSelectedFeed(self, hideReadEntries): base_query = """ FOR feed_entry_doc in feed_entry FILTER feed_entry_doc.feed == @feed_key""" if hideReadEntries: query = base_query + " AND feed_entry_doc.read == false " query = query + " SORT feed_entry_doc.updated RETURN feed_entry_doc" bind_vars = { 'feed_key': self.selectedFeed._key } results = self.database.AQLQuery(query, bind_vars=bind_vars) return [FeedEntry(doc) for doc in results] def _markSelectedFeedEntryRead(self): self.selectedFeedEntry.markRead() def updateAllFeeds(self): for feed in Feed.all_pending_update(self.database): FeedUpdater(self.database, self.preferences()).update(feed)