コード例 #1
0
ファイル: main.py プロジェクト: xweeta86/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 {}
コード例 #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
ファイル: dashboard.py プロジェクト: gj5615/bigquery-e2e
 def _make_request(self, token, num):
   return bigquery.tabledata().list(
     pageToken=token,
     maxResults=num,
     **self._kwargs)