Skip to content

Commit 986acdf

Browse files
committed
Codeforces-Scraper| gui.py| Added a short scraper to get codeforces profile
1 parent f944fa5 commit 986acdf

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Codeforces-Scraper/gui.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
from tkinter import simpledialog
4+
import urllib.parse
5+
import requests
6+
7+
def run():
8+
global show
9+
url = "https://codeforces.com/api/user.info?handles="
10+
h = e1.get()
11+
data = requests.get(url+h).json()
12+
if data['status'] == "OK":
13+
x = data['result'][0]
14+
a = [h, x['rating'], x['rank'], x['maxRating'], x['maxRank']]
15+
if show != None:
16+
for i in show.winfo_children():
17+
i.destroy()
18+
else:
19+
show = Frame(m)
20+
Label(show,text="").pack()
21+
Label(show,text="Handle: {}".format(a[0])).pack(anchor='center')
22+
Label(show,text="Current Rating: {}".format(a[1])).pack(anchor='center')
23+
Label(show,text="Current Rank: {}".format(a[2])).pack(anchor='center')
24+
Label(show,text="Max Rating: {}".format(a[3])).pack(anchor='center')
25+
Label(show,text="Max Rank: {}".format(a[4])).pack(anchor='center')
26+
show.pack()
27+
else:
28+
messagebox.showerror("Error", "User doesn't exist!")
29+
30+
m = Tk()
31+
show = None
32+
m.geometry("400x200")
33+
Label(m, text='Handle: ').pack(anchor="center")
34+
a = ""
35+
h=""
36+
e1 = Entry(m)
37+
e1.pack(anchor='center')
38+
sub = Button(m, text="Show Stats",command=run)
39+
sub.pack()
40+
m.mainloop()

0 commit comments

Comments
 (0)