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 {}
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 {}
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 {}
def _make_request(self, token, num): return bigquery.tabledata().list( pageToken=token, maxResults=num, **self._kwargs)