@@ -27,11 +27,14 @@ def __codechef(self):
27
27
soup = BeautifulSoup (page .text , 'html.parser' )
28
28
29
29
try :
30
- rank = soup .find ('div' , class_ = 'rating-number' ).text
30
+ rating = soup .find ('div' , class_ = 'rating-number' ).text
31
31
except AttributeError :
32
32
raise UsernameError ('User not Found' )
33
33
34
- rating = soup .find ('span' , class_ = 'rating' ).text
34
+ stars = soup .find ('span' , class_ = 'rating' ).text
35
+
36
+ highest_rating_container = soup .find ('div' , class_ = 'rating-header' )
37
+ highest_rating = highest_rating_container .find_next ('small' ).text .split ()[- 1 ].rstrip (')' )
35
38
36
39
rating_ranks_container = soup .find ('div' , class_ = 'rating-ranks' )
37
40
rating_ranks = rating_ranks_container .find_all ('a' )
@@ -117,9 +120,24 @@ def problems_solved_get():
117
120
118
121
return fully_solved , partially_solved
119
122
123
+ def user_details_get ():
124
+ header_containers = soup .find_all ('header' )
125
+ name = header_containers [1 ].find ('h2' ).text
126
+
127
+ user_details_section = soup .find ('section' , class_ = 'user-details' )
128
+ user_details_list = user_details_section .find_all ('li' )
129
+
130
+ return {'name' : name , 'username' : user_details_list [0 ].text .split ('★' )[- 1 ].rstrip ('\n ' ),
131
+ 'country' : user_details_list [1 ].text .split (':' )[- 1 ].strip (),
132
+ 'state' : user_details_list [2 ].text .split (':' )[- 1 ].strip (),
133
+ 'city' : user_details_list [3 ].text .split (':' )[- 1 ].strip (),
134
+ 'student/professional' : user_details_list [4 ].text .split (':' )[- 1 ].strip (),
135
+ 'institution' : user_details_list [5 ].text .split (':' )[- 1 ].strip ()}
136
+
120
137
full , partial = problems_solved_get ()
121
- details = {'status' : 'Success' , 'rank' : int (rank ), 'rating' : rating , 'global_rank' : int (global_rank ),
122
- 'country_rank' : int (country_rank ), 'contests' : contests_details_get (),
138
+ details = {'status' : 'Success' , 'rating' : int (rating ), 'stars' : stars , 'highest_rating' : int (highest_rating ),
139
+ 'global_rank' : int (global_rank ), 'country_rank' : int (country_rank ),
140
+ 'user_details' : user_details_get (), 'contests' : contests_details_get (),
123
141
'contest_ratings' : contest_rating_details_get (), 'fully_solved' : full , 'partially_solved' : partial }
124
142
125
143
return details
0 commit comments