forked from Abhijeet-AR/Competitive_Programming_Score_API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (19 loc) · 691 Bytes
/
main.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
from flask import Flask
from flask_restful import Api, Resource
from flask_cors import CORS
from details_soup import UserData, UsernameError, PlatformError
app = Flask(__name__)
CORS(app)
api = Api(app)
class Details(Resource):
def get(self, platform, username):
user_data = UserData(username)
try:
return user_data.get_details(platform)
except UsernameError:
return {'status': 'Failed', 'details': 'Invalid username'}
except PlatformError:
return {'stats': 'Failed', 'details': 'Invalid Platform'}
api.add_resource(Details,'/api/<string:platform>/<string:username>')
if __name__ == '__main__':
app.run()