예제 #1
0
 def handle(self, arg):
     device_id = arg.get('id', None)
     if not device_id:
         raise ValueError('id entry missing from argument')
     device = models.Device.get_by_device_id(device_id)
     if not device:
         raise KeyError('id %s not valid' % device_id)
     # Extract the UTC day from the timestamp in the record.
     ts = int(arg.get('ts', 0.0))
     day = datetime.utcfromtimestamp(ts)
     # Save the record using the streaming API.
     result = bigquery.tabledata().insertAll(
         projectId=PROJECT_ID,
         datasetId='logs',
         tableId='device_' + day.strftime("%Y%m%d"),
         body=dict(rows=[
             # Generate a suitable insert id.
             {
                 'insertId': ('%s:%d' % (device_id, ts)),
                 'json': arg
             }
         ])).execute()
     if 'error' in result or result.get('insertErrors'):
         logging.error('Insert failed: ' + unicode(result))
     return {}
예제 #2
0
파일: main.py 프로젝트: t4ku/bigquery-e2e
 def handle(self, arg):
     device_id = arg.get("id", None)
     if not device_id:
         raise ValueError("id entry missing from argument")
     device = models.Device.get_by_device_id(device_id)
     if not device:
         raise KeyError("id %s not valid" % device_id)
     # Extract the UTC day from the timestamp in the record.
     ts = int(arg.get("ts", 0.0))
     day = datetime.utcfromtimestamp(ts)
     # Save the record using the streaming API.
     result = (
         bigquery.tabledata()
         .insertAll(
             projectId=PROJECT_ID,
             datasetId="logs",
             tableId="device_" + day.strftime("%Y%m%d"),
             body=dict(
                 rows=[
                     # Generate a suitable insert id.
                     {"insertId": ("%s:%d" % (device_id, ts)), "json": arg}
                 ]
             ),
         )
         .execute()
     )
     if "error" in result or result.get("insertErrors"):
         logging.error("Insert failed: " + unicode(result))
     return {}
예제 #3
0
파일: main.py 프로젝트: gj5615/bigquery-e2e
 def handle(self, arg):
   device_id = arg.get('id', None)
   if not device_id:
     raise ValueError('id entry missing from argument')
   device = models.Device.get_by_device_id(device_id)
   if not device:
     raise KeyError('id %s not valid' % device_id)
   # Extract the UTC day from the timestamp in the record.
   ts = int(arg.get('ts', 0.0))
   day = datetime.utcfromtimestamp(ts)
   # Save the record using the streaming API.
   result = bigquery.tabledata().insertAll(
       projectId=PROJECT_ID,
       datasetId='logs',
       tableId='device_' + day.strftime("%Y%m%d"),
       body=dict(rows=[
           # Generate a suitable insert id.
           {'insertId': ('%s:%d' % (device_id, ts)),
            'json': arg}])).execute()
   if 'error' in result or result.get('insertErrors'):
     logging.error('Insert failed: ' + unicode(result))
   return {}
예제 #4
0
 def _make_request(self, token, num):
   return bigquery.tabledata().list(
     pageToken=token,
     maxResults=num,
     **self._kwargs)