Skip to content

Instantly share code, notes, and snippets.

@aoirint
Created May 8, 2023 06:27
Show Gist options
  • Save aoirint/964480a536edf7ea70b99ea89a6ba4da to your computer and use it in GitHub Desktop.
Save aoirint/964480a536edf7ea70b99ea89a6ba4da to your computer and use it in GitHub Desktop.
import requests
import csv
query = '''
mutation CreateSensorValue(
$objects: [SensorValue_insert_input!]!
) {
insert_SensorValue(objects: $objects) {
affected_rows
returning {
id
}
}
}
'''
with open('work/log.csv', 'r', encoding='utf-8') as fp:
reader = csv.DictReader(fp)
objects = []
for row in reader:
objects.append({
'key': 'l12_traffic_daily',
'value': int(row['daily_usage_bytes']),
'timestamp': row['timestamp'],
})
objects.append({
'key': 'l12_traffic_monthly',
'value': int(row['monthly_usage_bytes']),
'timestamp': row['timestamp'],
})
requests.post(
'https://hmapi.aoirint.com/v1/graphql',
headers={
'x-hasura-admin-secret': '**************',
},
json={
'query': query,
'variables': {
'objects': objects,
},
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment