Created
August 22, 2018 06:15
-
-
Save ecthiender/56ee681321975676585e7e08f3d93dbf to your computer and use it in GitHub Desktop.
This file contains 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 random | |
from datetime import datetime | |
import time | |
import json | |
import requests | |
query = """ | |
mutation { | |
insert_conditions (objects: [ | |
{ | |
time: "%s", | |
location: "%s", | |
temperature: %.2f, | |
humidity: %.2f | |
} | |
]) { | |
affected_rows | |
} | |
} | |
""" | |
url = 'http://<your-graphql-engine-endpoint>/v1alpha1/graphql' | |
headers = { | |
'x-hasura-access-key': '<your-access-key>' | |
} | |
location_choices = ['loc1', 'loc2', 'loc3', 'loc4', 'home', 'office'] | |
def mk_query(cur_time, loc, temp, humid): | |
q = query % (cur_time, loc, temp, humid) | |
print(q) | |
r = requests.post(url, data=json.dumps({'query': q}), headers=headers) | |
print(r.text) | |
while True: | |
temp = random.uniform(18.2, 39.89) | |
humid = random.uniform(40.34, 92.87) | |
loc = random.choice(location_choices) | |
cur_time = datetime.now().isoformat() | |
mk_query(cur_time, loc, temp, humid) | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If following the blog here, this has an issue where
cur_time
is a different timezone than the docker container (which uses UTC)Replace
with