summaryrefslogtreecommitdiff
path: root/api.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-01-28 16:41:01 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2017-01-28 16:41:09 +0100
commit9535cab8d794a01134b8dccfbf54ebf3eac65037 (patch)
treeda0dbc31f1db1a8ed8670ddf29353e891c8c86e3 /api.py
parent769fd6527b0a36cd59537953d34721d28fd62042 (diff)
downloadapigrabber-9535cab8d794a01134b8dccfbf54ebf3eac65037.tar.gz
apigrabber-9535cab8d794a01134b8dccfbf54ebf3eac65037.zip
api: get new matches more reliably, remove now unused `db.meta`
Diffstat (limited to 'api.py')
-rw-r--r--api.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/api.py b/api.py
index 46c8f72..1120c09 100644
--- a/api.py
+++ b/api.py
@@ -25,19 +25,17 @@ async def recrawl():
# TODO: insert API version (force update if changed)
# TODO: create database indices
# get or put when the last crawl was executed
- try:
- last_match_update = await db.meta("last_match_update")
- except KeyError:
- last_match_update = datetime.datetime(1, 1, 1).isoformat()
- await db.meta("last_match_update", last_match_update)
- nowiso = datetime.datetime.now().isoformat()
+ last_match_update = (await db.select(
+ "SELECT data->'attributes'->>'createdAt' AS created FROM match ORDER BY data->'attributes'->>'createdAt' DESC LIMIT 1")
+ )[0]["created"]
# crawl and upsert
matches = await api.matches_since(last_match_update)
if len(matches) > 0:
print("got a lot new data items: " + str(len(matches)))
+ else:
+ print("got no new matches.")
await db.upsert(matches, True)
- await db.meta("last_match_update", nowiso)
asyncio.ensure_future(recrawl_soon())