-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
107 lines (67 loc) · 2.66 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
from flask import Flask
from flask_restful import Resource, Api, reqparse
import scraper, json
app = Flask(__name__)
api = Api(app)
class MPList(Resource):
def get(self):
list = json.loads(scraper.mps_json)
return {"data": list}, 200
class MPVotes(Resource):
def get(self):
parser = reqparse.RequestParser() # initialize
parser.add_argument("personId", required=True)
args = parser.parse_args()
votes = scraper.scrape_mp_votes(args["personId"])
votes_json_string = json.dumps(votes, ensure_ascii=False, indent=4)
mp = next(
match for match in scraper.mp_list if match["person_id"] == args["personId"]
)
return {f"{mp['name']}_voting_data": votes}, 200
class MPName(Resource):
def get(self):
parser = reqparse.RequestParser() # initialize
parser.add_argument("personId", required=True)
args = parser.parse_args()
# mp_name = pass
mp = next(
match for match in scraper.mp_list if match["person_id"] == args["personId"]
)
return {"name": mp["name"]}, 200
class MPData(Resource):
def get(self):
parser = reqparse.RequestParser() # initialize
parser.add_argument("personId", required=True)
args = parser.parse_args()
# mp_name = pass
mp = next(
match for match in scraper.mp_list if match["person_id"] == args["personId"]
)
return {"mp_data": mp}, 200
class MPDatabyName(Resource):
def get(self):
parser = reqparse.RequestParser() # initialize
parser.add_argument("name", required=True)
args = parser.parse_args()
mp = next(match for match in scraper.mp_list if match["name"] == args["name"])
return {"mp_data": mp}, 200
class MPVotesbyName(Resource):
def get(self):
parser = reqparse.RequestParser() # initialize
parser.add_argument("name", required=True)
args = parser.parse_args()
mp = next(match for match in scraper.mp_list if match["name"] == args["name"])
votes = scraper.scrape_mp_votes(mp["person_id"])
votes_json_string = json.dumps(votes, ensure_ascii=False, indent=4)
return {f"{mp['name']}_voting_data": votes}, 200
api.add_resource(MPList, "/get_mp_list")
api.add_resource(MPVotes, "/get_mp_votes")
api.add_resource(MPName, "/get_mp_name")
api.add_resource(MPData, "/get_mp_data")
api.add_resource(MPDatabyName, "/get_mp_data_by_name")
api.add_resource(MPVotesbyName, "/get_mp_votes_by_name")
@app.route("/")
def index():
return "<h1> Deployed to Heroku</h1>"
if __name__ == "__main__":
app.run() # run our Flask app