Skip to content

Commit 741a305

Browse files
author
michael_cahana
committed
posting data to production site
1 parent 91cc378 commit 741a305

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

dummydata/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dummydata/makejson.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
var fs = require("fs")
22

3+
days_in_month = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
4+
35
function mkJson() {
46
var sensordata = []
57
var data_types = ['gas', 'pm10', 'pm2.5', 'temp', 'humidity']
68
var node_id_lat = {1: 42.0556589, 2: 42.0413013, 3: 42.0507029, 4: 42.074439, 5: 42.0611052}
79
var node_id_long = {1: -87.6831799, 2: -87.6800576, 3: -87.6741602, 4: -87.6842669, 5: -87.6765987}
810
for (var mo = 0; mo < 12; mo++) {
9-
for (var day = 1; day <= 28; day++) {
11+
len_month = days_in_month[mo]
12+
for (var day = 1; day <= len_month; day++) {
1013
for (var hr = 0; hr < 24; hr++) {
1114
var battery = (Math.random() * 5).toFixed(2)
1215
var created_at = new Date(2017, mo, day, hr);

dummydata/postdata.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import requests
3+
import time
4+
from random import randint
5+
6+
# note: pushed data up to 14
7+
up_to = 14
8+
# Tuesday, March 6, 11:20AM
9+
10+
# read in dummy data file created by makejson.js
11+
data = json.load(open('data.json'))
12+
13+
# specify site url
14+
site_url = 'https://sensorgridapi.knightlab.com/sensordata/'
15+
# local server site: 'http://127.0.0.1:8000/sensordata/'
16+
# production site: 'https://sensorgridapi.knightlab.com/sensordata/'
17+
18+
for i in range(up_to, len(data)):
19+
print('posting data ' + str(i))
20+
# posts data to whichever site is specified by the site_url
21+
r = requests.post(site_url, data=data[i])
22+
print(r)
23+
time.sleep(randint(15,60))

dummydata/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.14.2
2+

0 commit comments

Comments
 (0)