diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-02-26 15:59:32 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-02-26 15:59:32 +0100 |
| commit | ecfe701708795c2f35491dc64bd22421dc485992 (patch) | |
| tree | 43de6a14718d70a3c16894e7a652206edf36ed29 /api.py | |
| parent | bdcc5add4e5114746b47c4d481e316b7ee3415e4 (diff) | |
| download | apigrabber-ecfe701708795c2f35491dc64bd22421dc485992.tar.gz apigrabber-ecfe701708795c2f35491dc64bd22421dc485992.zip | |
store api data as one json per match
Diffstat (limited to 'api.py')
| -rw-r--r-- | api.py | 29 |
1 files changed, 6 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__))) @@ -60,17 +47,13 @@ class Worker(object): 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"], }) async def _work(self): |
