annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from argparse import ArgumentParser
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 from ArangoDb import ArangoDb
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 from backend.AbstractBackend import AbstractBackend
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 from Feed import Feed
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 from FeedEntry import FeedEntry
259
304917762618 implementation of feed updates
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 256
diff changeset
7 from FeedUpdater import FeedUpdater
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 from Preferences import Preferences
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 from pyArango.connection import Connection
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 """
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12 Backend that uses ArangoDB for persistence
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 """
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 class ArangoBackend(AbstractBackend):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 def __init__(self):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 super(ArangoBackend, self).__init__()
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 args = self._parse_arguments()
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 connection = Connection(arangoURL=args.dburl, username=args.user, password=args.password)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19 self.database = ArangoDb(connection[args.dbname])
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 self.prefs = None
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22 def _parse_arguments(self):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23 parser = ArgumentParser()
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24 parser.add_argument('--dburl', nargs='?', help='URL of the database', default='http://127.0.0.1:8529')
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 parser.add_argument('--dbname', nargs='?', help='name of the database', default='feedworm')
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26 parser.add_argument('--user', nargs='?', help='username for authenticating the database connection', required=True)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
27 parser.add_argument('--password', nargs='?', help='password for authenticating the database connection', required=True)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28 return parser.parse_known_args()[0]
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30 def preferences(self):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
31 if self.prefs is None:
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
32 self.prefs = Preferences(self.database)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
33 return self.prefs
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
34
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
35 def getUnreadFeeds(self):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
36 return Feed.get_unread(self.database)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
37
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
38 def _retrieveEntriesForSelectedFeed(self, hideReadEntries):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
39 base_query = """
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
40 FOR feed_entry_doc in feed_entry
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
41 FILTER feed_entry_doc.feed == @feed_key"""
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
42 if hideReadEntries:
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
43 query = base_query + " AND feed_entry_doc.read == false "
259
304917762618 implementation of feed updates
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 256
diff changeset
44 query = query + " SORT feed_entry_doc.updated RETURN feed_entry_doc"
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
45 bind_vars = { 'feed_key': self.selectedFeed._key }
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
46 results = self.database.AQLQuery(query, bind_vars=bind_vars)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
47 return [FeedEntry(doc) for doc in results]
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
48
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
49 def _markSelectedFeedEntryRead(self):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
50 self.selectedFeedEntry.markRead()
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
51
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
52 def updateAllFeeds(self):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
53 for feed in Feed.all_pending_update(self.database):
259
304917762618 implementation of feed updates
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 256
diff changeset
54 FeedUpdater(self.database, self.preferences()).update(feed)