Skip to content

Commit 2ebb6dd

Browse files
committed
added multiplatform requests
1 parent bc1039c commit 2ebb6dd

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It's not required but you can use it if you need multiple-platform requests (ex.
1717
### Steps
1818

1919
1. Create `fork`.
20-
2. Add your username in `usernames.json` in format below:
20+
2. Add your username in `users.json` in format below:
2121
```json
2222
{
2323
"USERNAME_YOU_NEED*": {

main.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,22 @@ def get_leetcode_info(username: str):
5555

5656
@app.get("/status")
5757
def get_status():
58-
return json.load(open("status.json", "r"))
58+
return json.load(open("status.json", "r"))
59+
60+
@app.get("/{username}")
61+
def get_all_ratings_from_username(username: str):
62+
with open('users.json') as file:
63+
users: dict = json.load(file)
64+
if username in users.keys():
65+
userdata = users[username]
66+
else:
67+
return {"error": "username not found!",
68+
"code": 1001}
69+
70+
body = {}
71+
if "leetcode" in userdata.keys():
72+
body['leetcode'] = get_leetcode_info(userdata['leetcode']) # TODO: use better functions
73+
if "codeforces" in userdata.keys():
74+
body['codeforces'] = get_codeforces_info(userdata['codeforces']) # TODO: use better functions
75+
76+
return body

usernames.json renamed to users.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"jayampatel": {
2+
"@jayampatel": {
33
"github": "jayam04",
44
"leetcode": "jayampatel",
55
"codeforces": "jayampatel"

0 commit comments

Comments
 (0)