-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
157 lines (94 loc) · 3.73 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import requests
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/')
def index():
names = []
logos = []
seasons = []
url = "https://api-football-v1.p.rapidapi.com/v2/leagues/country/england/2019"
headers = {
'x-rapidapi-host': "api-football-v1.p.rapidapi.com",
#api key
'x-rapidapi-key': ""
}
response = requests.request("GET", url, headers=headers )
result = response.json()
leagues = result['api']['leagues']
for league in leagues:
names.append(league['name'])
logos.append(league['logo'])
seasons.append(league['season'])
return render_template("lander.html", names = names, logos = logos, seasons = seasons)
# Route for navbar for each league
@app.route('/<string:name>/fixtures')
def dis_fix(name):
return render_template("fixture.html", name = name)
@app.route('/<string:name>/standings')
def dis_stand(name):
return render_template("standings.html", name = name)
# Route for fixtures
@app.route('/fixtures', methods = ['POST'])
def fixtures_func():
league_name = request.form.get('league')
url = "https://api-football-v1.p.rapidapi.com/v2/leagues/country/england/2019"
headers = {
'x-rapidapi-host': "api-football-v1.p.rapidapi.com",
#api key
'x-rapidapi-key': ""
}
response = requests.request("GET", url, headers=headers )
result = response.json()
leagues = result['api']['leagues']
for league in leagues:
if league['name'] == league_name :
league_id = league['league_id']
break
url = "https://api-football-v1.p.rapidapi.com/v2/fixtures/league/" +str(league_id)+ "/last/10"
headers = {
'x-rapidapi-host': "api-football-v1.p.rapidapi.com",
#api key
'x-rapidapi-key': ""
}
response = requests.request("GET", url, headers=headers)
resultlast = response.json()
url = "https://api-football-v1.p.rapidapi.com/v2/fixtures/league/" +str(league_id)+ "/next/10"
headers = {
'x-rapidapi-host': "api-football-v1.p.rapidapi.com",
#api key
'x-rapidapi-key': "#api key"
}
response = requests.request("GET", url, headers=headers)
if response.status_code!=200:
return jsonify({"success":False, "message":"Failure to get league id", "leag":league_name, "league":league_id, "url":str(url)})
resultnext = response.json()
return jsonify({ "success": True, "url": str(url) , "resultlast": resultlast, "resultnext": resultnext})
@app.route('/standings', methods = ['POST'])
def standing_func():
league_name = request.form.get('league')
url = "https://api-football-v1.p.rapidapi.com/v2/leagues/country/england/2019"
headers = {
'x-rapidapi-host': "api-football-v1.p.rapidapi.com",
#api key
'x-rapidapi-key': ""
}
response = requests.request("GET", url, headers=headers )
result = response.json()
leagues = result['api']['leagues']
for league in leagues:
if league['name'] == league_name :
league_id = league['league_id']
break
url1 = "https://api-football-v1.p.rapidapi.com/v2/leagueTable/" + str(league_id)
headers = {
'x-rapidapi-host': "api-football-v1.p.rapidapi.com",
#api key
'x-rapidapi-key': ""
}
response = requests.request("GET", url1, headers=headers)
if response.status_code!=200:
return jsonify({"success":False, "message":"Failure to get league id", "leag":league_name, "league":league_id, "url":str(url1)})
result = response.json()
return jsonify({ "success": True, "result": result})
if __name__== '__main__':
app.run()