-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgetscore.py
More file actions
115 lines (102 loc) · 3.1 KB
/
Copy pathgetscore.py
File metadata and controls
115 lines (102 loc) · 3.1 KB
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
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import simplejson as json
from google.appengine.ext import db
from update import Matches
class GetscoreByTeams(webapp.RequestHandler):
'''
RequestHandler class for /byteams page. Outputs
a JSON array of all the teams' score details.
'''
def _handlerequest(self):
self.t=self.request.get('teams')
self.output=[]
self.teamlist=self.t.split(',')
for tm in self.teamlist:
self.result=db.GqlQuery("SELECT * "
"FROM Matches "
"WHERE home_side = :1",
tm)
for r in self.result:
self.output.append({'home_side':r.home_side,
'away_side':r.away_side,
'score':r.score,
'time':r.time,
'date':r.date,
'competition':r.competition,
'live':r.live,
'finished':r.finished})
self.result=db.GqlQuery("SELECT * "
"FROM Matches "
"WHERE away_side = :1",
tm)
for r in self.result:
self.output.append({'home_side':r.home_side,
'away_side':r.away_side,
'score':r.score,
'time':r.time,
'date':r.date,
'competition':r.competition,
'live':r.live,
'finished':r.finished})
self.response.out.write(json.dumps(self.output))
def get(self):
self._handlerequest()
class GetscoreByCompetitions(webapp.RequestHandler):
'''
RequestHandler class for /bycompetitions page.
Outputs a JSON array of score details of all
matches in a competition.
'''
def _handlerequest(self):
self.c=self.request.get('competitions')
self.output=[]
self.competitions=self.c.split(',')
for ct in self.competitions:
self.result=db.GqlQuery("SELECT * "
"FROM Matches "
"WHERE competition = :1",
ct)
for r in self.result:
self.output.append({'home_side':r.home_side,
'away_side':r.away_side,
'score':r.score,
'time':r.time,
'date':r.date,
'competition':r.competition,
'live':r.live,
'finished':r.finished})
self.response.out.write(json.dumps(self.output))
def get(self):
self._handlerequest()
class GetMatches(webapp.RequestHandler):
'''
RequestHandler class for /allmatches page. Outputs
a JSON array of score details of all matches.
'''
def _handlerequest(self):
self.output=[]
self.result=db.GqlQuery("SELECT * "
"FROM Matches "
)
for r in self.result:
self.output.append({'home_side':r.home_side,
'away_side':r.away_side,
'score':r.score,
'time':r.time,
'date':r.date,
'competition':r.competition,
'live':r.live,
'finished':r.finished})
self.response.out.write(json.dumps(self.output))
def get(self):
self._handlerequest()
application = webapp.WSGIApplication(
[('/byteams', GetscoreByTeams),
('/bycompetitions',GetscoreByCompetitions),
('/allmatches',GetMatches)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()