-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
44 lines (31 loc) · 1012 Bytes
/
stats.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
from flask import Flask, request
from flask_cors import CORS, cross_origin
import json
import sqlite3
app = Flask(__name__)
CORS(app)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/frequency_play', methods=['GET'])
@cross_origin()
def collect():
conn = sqlite3.connect('play_stats.db')
c = conn.cursor()
c.execute("SELECT title, count(*) FROM stats WHERE type='PLAY' GROUP BY title")
response = c.fetchall()
conn.close()
data = []
for song in response:
data.append({'title': song[0], 'count': song[1]})
return json.dumps(data)
@app.route('/frequency_finish', methods=['GET'])
@cross_origin()
def frequency_finish():
conn = sqlite3.connect('play_stats.db')
c = conn.cursor()
c.execute("SELECT title, count(*) FROM stats WHERE type='FINISH' GROUP BY title")
response = c.fetchall()
conn.close()
data = []
for song in response:
data.append({'title': song[0], 'count': song[1]})
return json.dumps(data)