3
3
from fastapi import FastAPI
4
4
from fastapi .middleware .cors import CORSMiddleware
5
5
6
- import platform_scripts .codeforces as codeforces
6
+ import platform_scripts .codeforces as cf
7
+ import platform_scripts .codechef as chef
8
+ import platform_scripts .leetcode as lt
7
9
from leetcode import contest
8
10
9
11
app = FastAPI ()
17
19
allow_headers = ["*" ], # Set this to the HTTP headers you want to allow
18
20
)
19
21
22
+
20
23
@DeprecationWarning
21
24
@app .get ("/{username}/leetcode/contest" )
22
25
def get_leetcode_info (username : str ):
23
26
if username [0 ] != '@' :
24
27
return contest .get_contest_data (username )
25
28
29
+
26
30
@DeprecationWarning
27
31
@app .get ("/{username}/leetcode/contest/basic" )
28
32
def get_leetcode_info (username : str ):
29
- return contest .get_contest_basic (username )
33
+ data = contest .get_contest_basic (username )
34
+ data ['warning' ] = {"endpoint to be depreciated by end of 2023" }
35
+ return data
36
+
30
37
31
38
@DeprecationWarning
32
39
@app .get ("/{username}/leetcode/contest/basic/rank" )
33
40
def get_leetcode_rank (username : str ):
34
41
pass
35
42
return contest .get_contest_rank (username )
36
43
44
+
37
45
@DeprecationWarning
38
46
@app .get ("/{username}/leetcode/{query}" )
39
47
def get_leetcode_info_based_on_query (username : str , query : str ):
40
48
query = query .split ("+" )
41
49
pass
42
50
return contest .get_leetcode_info (username , query )
43
51
52
+
44
53
@app .get ("/codeforces/{username}" )
45
54
def get_codeforces_info (username : str ):
46
- return {
47
- "rating" : codeforces .get_current_rating (username )
48
- }
55
+ return cf .get_contest_data (username )
56
+
49
57
50
58
@app .get ("/leetcode/{username}" )
51
59
def get_leetcode_info (username : str ):
52
- return {
53
- "rating" : contest .get_contest_basic (username )["data" ]["userContestRanking" ]["rating" ]
54
- }
60
+ return lt .get_contest_data (username )
61
+
62
+
63
+ @app .get ("/codechef/{username}" )
64
+ def get_codechef_info (username : str ):
65
+ return chef .get_contest_data (username )
66
+
55
67
56
68
@app .get ("/status" )
57
69
def get_status ():
58
70
return json .load (open ("status.json" , "r" ))
59
71
72
+
60
73
@app .get ("/{username}" )
61
74
def get_all_ratings_from_username (username : str ):
62
75
with open ('users.json' ) as file :
@@ -65,12 +78,29 @@ def get_all_ratings_from_username(username: str):
65
78
userdata = users [username ]
66
79
else :
67
80
return {"error" : "username not found!" ,
68
- "code" : 1001 }
81
+ "code" : 1100 }
69
82
70
83
body = {}
71
84
if "leetcode" in userdata .keys ():
72
85
body ['leetcode' ] = get_leetcode_info (userdata ['leetcode' ]) # TODO: use better functions
73
86
if "codeforces" in userdata .keys ():
74
87
body ['codeforces' ] = get_codeforces_info (userdata ['codeforces' ]) # TODO: use better functions
88
+ if "codechef" in userdata .keys ():
89
+ body ['codechef' ] = chef .get_contest_rating (userdata ['codeforces' ]) # TODO: function is ok but not complete
90
+
91
+ return body
92
+
75
93
76
- return body
94
+ @app .get ("/{username}/leetcode" )
95
+ def get_leetcode_rating (username : str ):
96
+ if username [0 ] == "@" :
97
+ with open ('users.json' ) as file :
98
+ users : dict = json .load (file )
99
+ if username not in users .keys ():
100
+ return {"error" : "username not found!" ,
101
+ "code" : 1100 }
102
+ if "leetcode" not in users [username ].keys ():
103
+ return {"error" : f"leetcode id for { username } not found!" ,
104
+ "code" : 1101 }
105
+ username = users [username ]['leetcode' ]
106
+ return lt .get_contest_data (username )
0 commit comments