-
Notifications
You must be signed in to change notification settings - Fork 0
/
fanlytiks.py
executable file
·70 lines (58 loc) · 1.94 KB
/
fanlytiks.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
from flask import Flask, render_template, request, send_from_directory
import requests
import psycopg2
import sys
reload(sys)
sys.setdefaultencoding('utf8')
app = Flask(__name__)
# @app.route('/sitemap.xml')
# def static_from_root():
# return send_from_directory(app.static_folder, request.path[1:])
@app.route('/')
@app.route('/fanlytiks')
def index():
conn = psycopg2.connect(database = "aws", user = "milanmenezes", password = "nightfury", host = "milan-aws.crbk9i7trzoq.ap-south-1.rds.amazonaws.com", port = "5432")
#general info
info={}
cur = conn.cursor()
cur.execute("select count(*) from datastore;")
info["tcount"]=cur.fetchone()[0]
cur.close()
cur = conn.cursor()
cur.execute("select count(*) from (select distinct userid from datastore) as a;")
info["ucount"]=cur.fetchone()[0]
cur.close()
cur = conn.cursor()
cur.execute("select count(*) from datastore where media")
info["mcount"]=cur.fetchone()[0]
cur.close()
#latest tweets
cur = conn.cursor()
cur.execute("select distinct ttime, twtext from datastore order by ttime desc limit 10;")
latest=cur.fetchall()
cur.close()
#tweets with most retweets
cur = conn.cursor()
cur.execute("Select max(retweet) as r, twtext FROM datastore group by twtext order by r desc limit 10;")
retweet=cur.fetchall()
cur.close()
#tweets with most favourites
cur = conn.cursor()
cur.execute("Select max(favourite) as r, twtext FROM datastore group by twtext order by r desc limit 10;")
favourite=cur.fetchall()
cur.close()
#tweets per day
cur = conn.cursor()
cur.execute("select to_char(ttime,'YYYY-MM-DD') as day, count(to_char(ttime,'DD-MM-YY')) as tweets from datastore group by day order by day;")
tpd=cur.fetchall()
cur.close()
x=['x']
y=['tweets']
for i in tpd:
x.append(i[0])
y.append(int(i[1]))
tpd=[x,y]
# return str(data)
return render_template("index.html",info=info,tpd=tpd,latest=latest,retweet=retweet, favourite=favourite)
if __name__ == '__main__':
app.run(host='0.0.0.0')