#!/usr/bin/env python

import urllib
import urllib2
import time

public_hash     = '0l3qD2apX3U3xwaxj7Op'
private_hash    = 'D6aMgbljPahexPwxlMBg'
base_url        = 'https://data.sparkfun.com'
post_url        = base_url + '/input/' + public_hash

headers = {
	'Content-type': 'application/x-www-form-urlencoded',
	'Phant-Private-Key': private_hash
}

def main():
	while 1:

		ref_arquivo = open("/home/linaro/Desktop/leiturasensores.txt")
		linha = ref_arquivo.readline()
		print linha


		ref_arquivo.close()

		data = {}
		data['uv'],data['light'],data['ir'] = linha.split(",")

#		data['ir'] = raw_input("Infrared value: ")
#		data['light'] = raw_input("Light value: ")
#		data['uv'] = raw_input("UV Value: ")

		data = urllib.urlencode(data)
		post_request = urllib2.Request(post_url,data,headers)

		try: 
			post_response = urllib2.urlopen(post_request)
			print post_response.read()

		except URLError as e:
			print "Error: ", e.reason

		time.sleep(10)

if __name__ == "__main__":
	main()
