Skip to content

Instantly share code, notes, and snippets.

@ecthiender
Created August 22, 2018 06:15
Show Gist options
  • Save ecthiender/56ee681321975676585e7e08f3d93dbf to your computer and use it in GitHub Desktop.
Save ecthiender/56ee681321975676585e7e08f3d93dbf to your computer and use it in GitHub Desktop.
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)
@BryceBeagle
Copy link

If following the blog here, this has an issue where cur_time is a different timezone than the docker container (which uses UTC)

Replace

cur_time = datetime.now().isoformat()

with

cur_time = datetime.utcnow().isoformat()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment