-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaDay.py
More file actions
54 lines (45 loc) · 1.77 KB
/
Copy pathaDay.py
File metadata and controls
54 lines (45 loc) · 1.77 KB
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
import json
from TwitterDay import TwitterClient
import TwitterDay
import psycopg2
from time import gmtime, strftime
class ADay(object):
result = []
def __init__(self):
dayFetcher = TwitterDay
self.result = dayFetcher.main(0)
#do stuff here to get the days sentiment
#end of day store days sentiment
def getSentiment(self):
mdy = strftime("%Y-%m-%d", gmtime())
arrReturn = []
arrReturnInner = []
arrReturnInner.append({
'time': mdy,
'y': self.result[2] #Neutral
})
arrReturn.append(arrReturnInner)
arrReturnInner = []
arrReturnInner.append({
'time': mdy,
'y': self.result[0],
})
arrReturn.append(arrReturnInner)
arrReturnInner = []
arrReturnInner.append({
'time': mdy,
'y': self.result[1],
})
arrReturn.append(arrReturnInner)
#"""UPDATE main SET (positivenum, negativenum, neutralnum, totalnum) = ("""+self.result[0]+""", """ + self.result[1] + """, """ + self.result[2] + """, """ + self.result[3] + """) WHERE date IN(SELECT max(date) FROM myTable)"""
try:
conn = psycopg2.connect("dbname='' user='' host='' password='' sslmode='require'")
except:
print("I am unable to connect to the database")
cur = conn.cursor()
try:
cur.execute("""UPDATE main SET (positivenum, negativenum, neutralnum, totalnum) = ("""+str(self.result[0])+""", """ + str(self.result[1]) + """, """ + str(self.result[2]) + """, """ + str(self.result[3]) + """) WHERE date IN(SELECT max(date) FROM main);""")
conn.commit()
except:
print("failed to store data")
return json.dumps(arrReturn)