-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quashnet.py
executable file
·78 lines (60 loc) · 2.23 KB
/
Quashnet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#gfiske
#November 2016
#CCRO project
# import the modules
try:
import urllib
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
import json
import base64
import ConfigParser
except:
print "Cannot import one or more module"
import sys
sys.exit(1)
###############################################################
config = ConfigParser.RawConfigParser()
config.read('/home/gfiske/Data/python_scripts/gfiske.cfg')
db_user = config.get('section1', 'db_user')
db_passwd = config.get('section1', 'db_passwd')
g_user = config.get('section1', 'g_user')
g_passwd = config.get('section1', 'g_passwd')
db_user = db_user.decode('base64','strict')
db_passwd = db_passwd.strip("'")
email = g_user.decode('base64','strict')
password = g_passwd.decode('base64','strict')[0:15]
chdb_user = config.get('section1', 'chdb_user')
chdb_user = chdb_user.strip("'")
chdb_passwd = config.get('section1', 'chdb_passwd')
chdb_passwd = chdb_passwd.strip("'")
###############################################################
#########################################
# PULL FROM CASCADE DEVICE #
#########################################
url = "https://www.dropbox.com/s/24cmcg6zsakxn8w/Quashnet-001?dl=1"
u = urllib.urlopen(url)
data = u.read()
u.close()
date, time, temp = data.split()
dateTime = date + " " + time
#convert temp to decimal value
temp = int(temp) * 0.001
#print "date: " + date
#print "time: " + time
#print "temperature: " + str(temp)
#print "dateTime"
#########################################
# Update Sheet #
#########################################
try:
#enter the data into the google spreadsheet
rowToAdd = (date, time, str(temp), dateTime, str(temp))
json_key = json.load(open('/home/gfiske/Data/python_scripts/raspPi-e0a08639ebab.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
g = gspread.authorize(credentials)
worksheet = g.open('Quashnet_temperature').get_worksheet(0)
worksheet.append_row(rowToAdd)
except:
print "update spreadsheet failed"