Update example source with new fetch signature and builtin
This commit is contained in:
parent
24c393d41f
commit
7c29071b23
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user