-
Notifications
You must be signed in to change notification settings - Fork 1
/
cc_rating.py
59 lines (51 loc) · 1.41 KB
/
cc_rating.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
# -*- coding: utf-8 -*-
"""
@author: Parikansh
"""
import os.path
import requests
from bs4 import BeautifulSoup
def get_num(x):
return int(''.join(ele for ele in x if ele.isdigit()))
# List of CC Usernames
usernames = []
if os.path.exists('users.txt'):
infile = open('users.txt')
usernames.extend([word for word in infile.read().split()])
else:
myname = input("Enter Codechef UserId : ")
usernames.append(myname)
myfile = open('users.txt','a')
myfile.write("%s\n" % myname)
choice = 0
while choice!=3:
print("1. View Ratings")
print("2. Add Friends")
print("3. Exit")
choice = input("Enter option : ")
choice = get_num(choice)
if choice==1:
print("Loading Ratings from Codechef")
print(" ")
if len(usernames)==0:
print("Please Add Friends")
for userid in usernames:
page = requests.get("https://www.codechef.com/users/" + userid)
soup = BeautifulSoup(page.content, 'html.parser')
stats = soup.find(class_="rating-header")
if stats:
rating = stats.find(class_="rating-number").get_text()
rating_num = get_num(rating)
print('{:20}| {:5}'.format(userid , rating_num))
else:
print("Error in connection for " + userid)
print(" ")
if choice==2:
new_user = input("Enter a new username: ")
usernames.append(new_user)
myfile = open('users.txt','a')
myfile.write("%s\n" % new_user)
print("New user added !")
print(" ")
if choice==3:
print(" Thanks. Bye!")