diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-02-27 14:35:14 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-02-27 14:35:14 +0100 |
| commit | e563704f337d47c1f5bbd632d053b275d443ec49 (patch) | |
| tree | 9605f9e9dcd2cb176822b6ec9dfaffa5804896df /api.py | |
| parent | 96916f5f501a6392deae6174bbb687fe10c0f400 (diff) | |
| parent | f54bb387475cd19e2f8d32cca131e2abb5eea8fd (diff) | |
| download | apigrabber-e563704f337d47c1f5bbd632d053b275d443ec49.tar.gz apigrabber-e563704f337d47c1f5bbd632d053b275d443ec49.zip | |
Merge branch 'player-upsert'
Diffstat (limited to 'api.py')
| -rw-r--r-- | api.py | 36 |
1 files changed, 13 insertions, 23 deletions
@@ -31,21 +31,8 @@ class Worker(object): async with self._pool.acquire() as con: await con.execute(""" CREATE TABLE IF NOT EXISTS - match ( - id TEXT PRIMARY KEY, - type TEXT DEFAULT 'match', - attributes JSONB, - relations JSONB - ) - """) - await con.execute(""" - CREATE TABLE IF NOT EXISTS - player ( - id TEXT PRIMARY KEY, - type TEXT DEFAULT 'player', - attributes JSONB - ) - """) + match (id TEXT PRIMARY KEY, data JSONB) + """) root = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) @@ -56,21 +43,24 @@ class Worker(object): """Finish a job.""" api = crawler.Crawler(self._apitoken) logging.debug("%s: getting matches from API", jobid) + # if a player is queried, pass that information to processor + if "filter[playerNames]" in payload["params"]: + playername = payload["params"]["filter[playerNames]"] + else: + playername = "" + async with self._pool.acquire() as con: async for data in api.matches(region=payload["region"], params=payload["params"]): logging.debug("%s: inserting into database", jobid) - objects = await con.fetch(self._insertquery, json.dumps(data)) - logging.info("%s: inserted %s", jobid, - {t: len([s for s in objects if s["type"] == t]) - for t in set([e["type"] for e in objects])} - ) - for obj in objects: + matchids = await con.fetch(self._insertquery, json.dumps(data)) + logging.info("%s: inserted %s matches", jobid, len(matchids)) + for matchid in matchids: await self._queue.request(jobtype="process", priority=priority, payload={ - "id": obj["id"], - "type": obj["type"] + "id": matchid["id"], + "playername": playername }) async def _work(self): |
