Thursday, January 3, 2013

a Python script to fetch one COSM datastream v0.1

This is a simple Python script to fetch one COSM / pachube datastream.



Cosm is a secure platform for Internet of Things devices and products. Its API and web service provide real-time control and data storage.

Unfortunately on these days cosm.com does not provide any software to download a datastream data, so i've build this script, which use cosm api to download datapoints of a datastream.

Before launch the script, you have to open the script with an editor and setup some parameters.

#setup your cosm account data here
#set cosm key
COSM_APIKEY="YOUR_COSM_APIKEY_HERE"
#set cosm feed id
COSM_FEEDID=YOUR_FEED_ID_HERE
#set cosm datastream
COSM_DATASTREAM=YOUR_DATASTREAM_HERE

#download datastream backward from DATETO to DATEFROM, with datapoint interval of INTERVAL (seconds), and backward step of DATEINTERVAL (hour)
#cosm history interval request
INTERVAL=0
#get backward from DATETO to DATEFROM
DATEFROM=datetime(2012,12,5,15,45,0)
DATETO=datetime(2012,12,8,15,45,0)
#interval between requested data (in hour)
DATEINTERVAL=1

#output file name, and conversion (date) to csv format
#set output file
OUTFILE="out.csv"
#convert cosm data
CONVERTDATA=1


Code

Notes
  • read risk disclaimer
  • excuse my bad english