-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
123 lines (98 loc) · 2.51 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import json
import requests
from flask import Flask, send_from_directory, Response
from flask_cors import CORS
from overwatchGameScraper import pullOverwatchVideo
app = Flask(__name__)
CORS(app)
@app.route('/')
def index():
return send_from_directory('static', 'index.html')
@app.route('/images/ranks/<medal>')
def rank(medal):
ranks = {
"bronze": "rank-1.png",
"silver": "rank-2.png",
"gold": "rank-3.png",
"platinum": "rank-4.png",
"diamond": "rank-5.png",
"master": "rank-6.png",
"grandmaster": "rank-7.png"
}
try:
return send_from_directory('static/images/ranks/', ranks[medal])
except:
return send_from_directory('static/images/ranks/', medal)
@app.route('/<path:path>')
def root(path):
return send_from_directory('static', path)
@app.route('/video/<gamertag>')
def getVideo(gamertag):
j = json.dumps(pullOverwatchVideo(gamertag))
r = Response(j)
r.headers['Content-Type'] = "application/json"
return r
@app.route('/overwatch/<platform>/<gamertag>')
def stats(platform, gamertag):
r = requests.get("https://owapi.net/api/v3/u/"+ gamertag + "/blob?platform=" + platform, headers={"User-Agent": "Overwatch Stats App v0.1"})
mapping = {
"game_stats": {
"medals_gold": {
"title": "Gold Medals",
},
"kpd": {
"title": "Kills per Death",
},
"multikill_best": {
"title": "Best Multikill",
},
"solo_kills_most_in_game": {
"title": "Most Solo Kills",
},
"kill_streak_best": {
"title": "Best Killstreak",
},
"time_played": {
"title": "Time Played",
"suffix": "Hours"
},
"eliminations": {
"title": "Eliminations"
}
}
}
gamemodes = [
"competitive",
"quickplay"
]
data = {}
stats = r.json()
for mode in gamemodes:
s = {}
for title, obj in mapping.iteritems():
s[title] = {}
for k, v in obj.iteritems():
s[title][k] = {}
for key,value in v.iteritems():
s[title][k][key] = value
if k != 'title':
s[title][k]['stat'] = stats['any']['stats'][mode][title][k]
data[mode] = s
# for mode, val in data.iteritems():
#
# for key, value in mapping.iteritems():
# data[mode][key] = value;
#
# for k, v in value.iteritems():
# print(mode, k, v)
# data[mode][key][k] = v
#
# if k != 'title':
# data[mode][key][k]['stat'] = stats['any']['stats'][mode][key][k]
data["all"] = stats['any']
j = json.dumps(data)
r = Response(j)
r.headers['Content-Type'] = "application/json"
return r
if __name__ == '__main__':
app.run('0.0.0.0', port=80, debug=True)