Last active
September 21, 2017 19:07
-
-
Save fredrike/e825f2c7e6158e44e508 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
""" | |
Change the constants below. | |
""" | |
fileName = "INSERT FILENAME" | |
API = "INSERT API-WRITE-KEY" | |
nodeID = 13 | |
urlString = "http://emoncms.org/input/bulk.json?time=%d&apikey=%s&data=[" | |
import pandas as pd | |
import numpy as np | |
import requests | |
d = pd.read_csv(fileName, sep=";", parse_dates=[0], decimal=",") | |
d = d.sort_values(by=d.columns[0]).reset_index(drop=True) | |
if d.iloc[:,0].min() == d.iloc[0,0]: | |
print "First row is the smallest" | |
row = 0 | |
else: | |
print "Could not find smallest value" | |
row = d.shape[0] - 1 | |
print "Start time", d.iloc[row,0] | |
print "Start with acceesing this url and create a feed." | |
print ((urlString + "[%d,%d,%f]]") % | |
(d.iloc[row,0].value // 10 ** 9, API, 0, nodeID, 0.0)) | |
chunksize = 24 | |
for row in range(0, d.shape[0]): | |
if not row % chunksize: | |
if string is not "": | |
string = string[:-1] + "]" | |
r = requests.get(string) | |
print row, r.text, | |
timestamp = d.iat[row,0].value // 10 ** 9 | |
string = urlString % (timestamp, API) | |
csv = "[%d,%d,%f]," % ((d.iat[row,0].value // 10 ** 9) - timestamp, nodeID, d.iat[row,1]) | |
string += csv | |
print row | |
string = string[:-1] + "]" | |
r = requests.get(string) | |
print string | |
print r.text | |
print "End time", (d.iat[row,0].value // 10 ** 9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment