Created
May 8, 2023 06:27
-
-
Save aoirint/964480a536edf7ea70b99ea89a6ba4da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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