-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaYear.py
More file actions
63 lines (51 loc) · 1.68 KB
/
Copy pathaYear.py
File metadata and controls
63 lines (51 loc) · 1.68 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
55
56
57
58
59
60
61
62
63
import json
import psycopg2
from time import gmtime, strftime
from datetime import date, datetime
from flask.json import jsonify
class AYear(object):
rows = []
def __init__(self):
mdy = strftime("%Y-%m-%d", gmtime())
# SELECT * FROM main WHERE date >= '2017-05-02' ORDER BY date ASC LIMIT 30
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("""SELECT * FROM main WHERE date <= '""" + mdy + """"' ORDER BY date DESC LIMIT 365""")
except:
print("failed to store data")
self.rows = cur.fetchall()
def getSentiment(self):
days = []
arrReturnInner = []
for row in self.rows:
arrReturnInner.append({
'time': row[0].isoformat(),
'y': row[3] # Neutral
})
days.append(arrReturnInner)
arrReturnInner = []
for row in self.rows:
arrReturnInner.append({
'time': row[0].isoformat(),
'y': row[1],
})
days.append(arrReturnInner)
arrReturnInner = []
for row in self.rows:
arrReturnInner.append({
'time': row[0].isoformat(),
'y': row[2],
})
days.append(arrReturnInner)
# days.append({
# 'date': row[0].isoformat(),
# 'positiveNum': row[1],
# 'negativeNum': row[2],
# 'neutralNum': row[3],
# 'totalNum': row[4]
# })
return json.dumps(days)