Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#995 Updated the output format. Updated scraper to handle errors and … #996

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scrape_up/espncricinfo/espncricinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ def get_livescores(self):
live_scores.append(match_details)
return live_scores
except:
return live_scores
return live_scores
37 changes: 24 additions & 13 deletions src/scrape_up/geeksforgeeks/geeksforgeeks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,32 @@ def get_profile(self):
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, "html.parser")
main_info = soup.find("div", class_="AuthLayout_head_content__ql3r2")
user_data = []

username = main_info.find(
"div",
class_="profilePicSection_head_userHandleAndFollowBtnContainer_userHandle__p7sDO",
).text
).text.strip()
collage_rank = main_info.find(
"span", class_="profilePicSection_head_userRankContainer_rank__abngM"
).text
).text.strip()
collage = main_info.find(
"div", class_="educationDetails_head_left--text__tgi9I"
).text
).text.strip()
languages = main_info.find(
"div", class_="educationDetails_head_right--text__lLOHI"
).text
).text.strip()
campus_ambaasder = soup.find(
"a", class_="basicUserDetails_head_CA--text__IoHEU"
).text
).text.strip()
current_potd_streak = main_info.find(
"div", class_="circularProgressBar_head_mid_streakCnt__MFOF1 tooltipped"
).text
).text.strip()
score = main_info.find_all(
"div", class_="scoreCard_head_card_left--score__pC6ZA"
)
overall_coding_score = score[0].text
total_problem_solved = score[1].text
monthly_coding_score = score[2].text
overall_coding_score = score[0].text.strip()
total_problem_solved = score[1].text.strip()
monthly_coding_score = score[2].text.strip()

user_data = {
"username": username,
Expand All @@ -85,9 +84,21 @@ def get_profile(self):
"campus_ambassader": campus_ambaasder,
}

return user_data
except:
return None
formatted_output = (
f"Username: {user_data['username']}\n"
f"College Name: {user_data['collage_name']}\n"
f"College Rank: {user_data['collage_rank']}\n"
f"Overall Coding Score: {user_data['score']['overall_coding_score']}\n"
f"Monthly Coding Score: {user_data['score']['monthly_coding_score']}\n"
f"Languages Used: {user_data['languages_used']}\n"
f"Current POTD Streak: {user_data['current_potd_streak']}\n"
f"Total Problems Solved: {user_data['total_problem_solved']}\n"
f"Campus Ambassador: {user_data['campus_ambassader']}"
)

return formatted_output
except Exception as e:
return f"An error occurred: {e}"


gfg = Geeksforgeeks(user="nikhil25803")
Expand Down
1 change: 0 additions & 1 deletion src/scrape_up/pinterest/pinterest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,3 @@ def get_pin_details(self, pin_url):
}
except Exception as e:
return None

1 change: 0 additions & 1 deletion src/test/espncricinfo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class ESPNTest(unittest.TestCase):

def test_connection(self):
instance = Espncricinfo()
self.assertTrue(
Expand Down
4 changes: 2 additions & 2 deletions src/test/pinterest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_get_today(self):
self.assertIn("image", topic)

def test_get_photo(self):
url = "https://pin.it/1ZhgQA5AG"
url = "https://pin.it/1ZhgQA5AG"
photo = self.pinterest.get_photo(url)
if photo:
self.assertIn("alt", photo)
Expand All @@ -33,7 +33,7 @@ def test_search_pins(self):
self.assertIn("image", pin)

def test_get_pin_details(self):
pin_url = "https://pin.it/1ZhgQA5AG"
pin_url = "https://pin.it/1ZhgQA5AG"
details = self.pinterest.get_pin_details(pin_url)
if details:
self.assertIn("title", details)
Expand Down