From 7c29071b23e849ab320427148b9f3a45f630ce17 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 14 Jun 2019 12:50:59 -0700 Subject: [PATCH] Update example source with new fetch signature and builtin --- inquisitor/dungeon.py | 4 +++- inquisitor/item.py | 6 +++--- sources/example.py | 24 +++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/inquisitor/dungeon.py b/inquisitor/dungeon.py index 82f2085..fed50c3 100644 --- a/inquisitor/dungeon.py +++ b/inquisitor/dungeon.py @@ -125,11 +125,13 @@ class DungeonCell(): f.write(str(self.state)) 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. prior_item_ids = [item_id for item_id in self] + logger.debug("Found {} prior items".format(len(prior_item_ids))) # Get the new items. new_items = source.fetch_new(self.state, args) + logger.debug("Fetched {} items".format(len(new_items))) self.save_state() new_count = del_count = 0 for item in new_items: diff --git a/inquisitor/item.py b/inquisitor/item.py index 2525a80..b5f7f87 100644 --- a/inquisitor/item.py +++ b/inquisitor/item.py @@ -7,7 +7,7 @@ import logging 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 item = { '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: item['link'] = link - if time is not None: - item['time'] = time + if ts is not None: + item['time'] = ts if author is not None: item['author'] = author if body is not None: diff --git a/sources/example.py b/sources/example.py index 2fe6459..00f02f7 100644 --- a/sources/example.py +++ b/sources/example.py @@ -1,6 +1,8 @@ """ 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 from datetime import date @@ -10,17 +12,13 @@ import time SOURCE = "examplesource" -def fetch_new(state): +def fetch_new(state, args): now = date.today() - item = { - 'id': '{}-{}-{}'.format(now.year, now.month, now.day), - 'source': SOURCE, - 'active': True, - 'time': time.time(), - 'created': time.time(), - 'title': "Today is {}-{}-{}".format(now.year, now.month, now.day), - #'link': - #'author': - #'body': - } + item = create_item( + SOURCE, + '{}-{}-{}'.format(now.year, now.month, now.day), + "Today is {}-{}-{}".format(now.year, now.month, now.day), + ts=time.time(), + body=args + ) return [item]