-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
executable file
·39 lines (30 loc) · 1009 Bytes
/
server.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
#!/usr/bin/env python3
from flask import Flask, jsonify
from collections import Counter
import sys
import wikiedits
app = Flask(__name__)
@app.route('/static/<path:path>')
def serve_static(path):
return send_from_directory('static', path)
@app.route('/edits/<username>')
def get_edits(username):
edits = list(wikiedits.get_edits(username, time_limit=365))
return jsonify(edits)
@app.route('/day_edits/<username>/<date>')
def get_edits_for_day(username, date):
edits = list(wikiedits.get_edits_for_day(username, date))
return jsonify(edits)
@app.route('/edits_per_day/<username>')
def get_edits_per_day(username):
date_counts = {}
for date, count in wikiedits.get_edits_per_day(username, time_limit=365):
date_counts[date] = count
return jsonify(date_counts)
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1].lower().startswith('dev'):
app.debug = True
app.run(host='127.0.0.1', port=5000)
else:
app.debug = False
app.run(host='0.0.0.0', port=80)