diff --git a/details_soup.py b/details_soup.py index a09ad02..f257b3f 100644 --- a/details_soup.py +++ b/details_soup.py @@ -56,13 +56,14 @@ def __codechef(self): global_rank = rating_ranks[0].strong.text country_rank = rating_ranks[1].strong.text - if global_rank != 'NA': + if global_rank != 'NA' and global_rank != 'Inactive': global_rank = int(global_rank) country_rank = int(country_rank) def contests_details_get(): rating_table = soup.find('table', class_='rating-table') - + if not rating_table: + return [] rating_table_rows = rating_table.find_all('td') '''Can add ranking url to contests''' @@ -146,18 +147,24 @@ def problems_solved_get(): return fully_solved, partially_solved def user_details_get(): + user_details_attribute_exclusion_list = {'username', 'link', 'teams list', 'discuss profile'} + header_containers = soup.find_all('header') name = header_containers[1].find('h1', class_="h2-style").text user_details_section = soup.find('section', class_='user-details') user_details_list = user_details_section.find_all('li') - return {'name': name, 'username': user_details_list[0].text.split('★')[-1].rstrip('\n'), - 'country': user_details_list[1].text.split(':')[-1].strip(), - 'state': user_details_list[2].text.split(':')[-1].strip(), - 'city': user_details_list[3].text.split(':')[-1].strip(), - 'student/professional': user_details_list[4].text.split(':')[-1].strip(), - 'institution': user_details_list[5].text.split(':')[-1].strip()} + user_details_response = {'name': name, 'username': user_details_list[0].text.split('★')[-1].rstrip('\n')} + for user_details in user_details_list: + attribute, value = user_details.text.split(':')[:2] + attribute = attribute.strip().lower() + value = value.strip() + + if attribute not in user_details_attribute_exclusion_list: + user_details_response[attribute] = value + + return user_details_response full, partial = problems_solved_get() details = {'status': 'Success', 'rating': int(rating), 'stars': stars, 'highest_rating': int(highest_rating), diff --git a/requirements.txt b/requirements.txt index c44676a..74267db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,9 +13,10 @@ itsdangerous==1.1.0 Jinja2==2.11.3 MarkupSafe==1.1.1 pytz==2019.3 -requests==2.22.0 +requests==2.27.1 +selenium==3.141.0 six==1.14.0 soupsieve==1.9.5 -urllib3==1.26.5 +urllib3==1.26.9 Werkzeug==0.16.1 selenium==3.141.0 \ No newline at end of file