Skip to content

Instantly share code, notes, and snippets.

@fredrike
Last active September 21, 2017 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrike/e825f2c7e6158e44e508 to your computer and use it in GitHub Desktop.
Save fredrike/e825f2c7e6158e44e508 to your computer and use it in GitHub Desktop.
"""
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
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