Update example source with new fetch signature and builtin

This commit is contained in:
Tim Van Baak 2019-06-14 12:50:59 -07:00
parent 24c393d41f
commit 7c29071b23
3 changed files with 17 additions and 17 deletions

View File

@ -125,11 +125,13 @@ class DungeonCell():
f.write(str(self.state)) f.write(str(self.state))
def update_from_source(self, source, args): def update_from_source(self, source, args):
logger.info("Updating source {}".format(self.name)) logger.info("Updating source '{}'".format(self.name))
# Get the ids of the existing items. # Get the ids of the existing items.
prior_item_ids = [item_id for item_id in self] prior_item_ids = [item_id for item_id in self]
logger.debug("Found {} prior items".format(len(prior_item_ids)))
# Get the new items. # Get the new items.
new_items = source.fetch_new(self.state, args) new_items = source.fetch_new(self.state, args)
logger.debug("Fetched {} items".format(len(new_items)))
self.save_state() self.save_state()
new_count = del_count = 0 new_count = del_count = 0
for item in new_items: for item in new_items:

View File

@ -7,7 +7,7 @@ import logging
logger = logging.getLogger("inquisitor.item") logger = logging.getLogger("inquisitor.item")
def create_item(source, item_id, title, link=None, time=None, author=None, body=None): def create_item(source, item_id, title, link=None, ts=None, author=None, body=None):
import time import time
item = { item = {
'id': item_id, 'id': item_id,
@ -18,8 +18,8 @@ def create_item(source, item_id, title, link=None, time=None, author=None, body=
} }
if link is not None: if link is not None:
item['link'] = link item['link'] = link
if time is not None: if ts is not None:
item['time'] = time item['time'] = ts
if author is not None: if author is not None:
item['author'] = author item['author'] = author
if body is not None: if body is not None:

View File

@ -1,6 +1,8 @@
""" """
An example itemsource that produces an item with the current date. An example itemsource that produces an item with the current date.
Fetch new items with `python inquisitor update --sources examplesource`. ANy args provided will be added to the item body.
Fetch new items with `python inquisitor update --sources example`
or `--sources example:argument`.
""" """
# Standard library imports # Standard library imports
from datetime import date from datetime import date
@ -10,17 +12,13 @@ import time
SOURCE = "examplesource" SOURCE = "examplesource"
def fetch_new(state): def fetch_new(state, args):
now = date.today() now = date.today()
item = { item = create_item(
'id': '{}-{}-{}'.format(now.year, now.month, now.day), SOURCE,
'source': SOURCE, '{}-{}-{}'.format(now.year, now.month, now.day),
'active': True, "Today is {}-{}-{}".format(now.year, now.month, now.day),
'time': time.time(), ts=time.time(),
'created': time.time(), body=args
'title': "Today is {}-{}-{}".format(now.year, now.month, now.day), )
#'link':
#'author':
#'body':
}
return [item] return [item]