From fae1a33a1436590e241b769f1e7804fa5fddc563 Mon Sep 17 00:00:00 2001 From: jayadhar gandham <42913445+JayadharGj@users.noreply.github.com> Date: Fri, 2 Feb 2024 22:40:15 -0500 Subject: [PATCH 1/6] Create leetcode.py adding scrapping endpoints for leetcode data --- leetcode.py | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 leetcode.py diff --git a/leetcode.py b/leetcode.py new file mode 100644 index 0000000..57f475e --- /dev/null +++ b/leetcode.py @@ -0,0 +1,157 @@ +from bs4 import BeautifulSoup +import requests +from flask import * +import json +from flask_cors import CORS + +app = Flask(__name__) +CORS(app) + + +@app.route("/", methods=["GET"]) # creating an endpoint for GET request +def home_page(): + return "

Hello, Welcome to LEETCODE SCRAPPER's HOMEPAGE

To get someone's LeetCode Account Details send GET request to the below URL

https://subrata-rudra-leetcode-scrapper.onrender.com/user/?user=LEETCODE_USERNAME_OF_USER

" + + +@app.route("/user/", methods=["GET"]) +def request_data(): + username = str(request.args.get("user")) + + base_url = "https://leetcode.com/" + + final_url = base_url + username + + html_text = requests.get(final_url).text + + soup = BeautifulSoup(html_text, "lxml") + + username = soup.find( + "div", class_="text-label-3 dark:text-dark-label-3 text-xs" + ).text + + candidate_name = soup.find( + "div", + class_="text-label-1 dark:text-dark-label-1 break-all text-base font-semibold", + ).text + + candidate_rank = soup.find( + "span", class_="ttext-label-1 dark:text-dark-label-1 font-medium" + ).text + + contest_attended = soup.find_all( + "div", class_="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]" + )[1].text + + contest_rating = soup.find( + "div", class_="text-label-1 dark:text-dark-label-1 flex items-center text-2xl" + ).text + + contest_global_ranking = soup.find( + "div", class_="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]" + ).text + + total_problem_solved = soup.find( + "div", class_="text-[24px] font-medium text-label-1 dark:text-dark-label-1" + ).text + + problems_solved = soup.find_all( + "span", + class_="mr-[5px] text-base font-medium leading-[20px] text-label-1 dark:text-dark-label-1", + ) + + # total_submissions = soup.find( + # "span", class_="mr-[5px] text-base font-medium lc-md:text-xl" + # ).text + + language_used = soup.find_all( + "span", + class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full text-label-3 dark:text-dark-label-3 bg-fill-3 dark:bg-dark-fill-3 notranslate", + ) + + # total_active_days = soup.find_all( + # "span", class_="font-medium text-label-2 dark:text-dark-label-2" + # )[3].text + + # max_streak = soup.find_all( + # "span", class_="font-medium text-label-2 dark:text-dark-label-2" + # )[4].text + + solved_problem = soup.find_all( + "span", class_="text-label-1 dark:text-dark-label-1 font-medium line-clamp-1" + ) + + topics_covered = soup.find_all( + "span", + class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full bg-fill-3 dark:bg-dark-fill-3 cursor-pointer transition-all hover:bg-fill-2 dark:hover:bg-dark-fill-2 text-label-2 dark:text-dark-label-2", + ) + + badges_earned = soup.find_all( + "img", class_="h-full w-full cursor-pointer object-contain" + ) + + most_recent_badge = soup.find( + "div", class_="text-label-1 dark:text-dark-label-1 text-base" + ).text + + # last_solved = soup.find( + # "span", + # class_="text-label-3 dark:text-dark-label-3 hidden whitespace-nowrap lc-md:inline", + # ).text + + language_used_list = [] + ind = 0 + for language in language_used: + language_used_list.insert(ind, language.text) + ind = ind + 1 + + solved_problem_list = [] + ind = 0 + for problem in solved_problem: + solved_problem_list.insert(ind, problem.text) + ind = ind + 1 + + topics_covered_list = [] + ind = 0 + for topic in topics_covered: + topics_covered_list.insert(ind, topic.text) + ind = ind + 1 + + badges_earned_list = [] + ind = 0 + for badge in badges_earned: + badges_earned_list.insert(ind, badge["alt"]) + ind = ind + 1 + + solved_problem_json = json.dumps(solved_problem_list) + topics_covered_json = json.dumps(topics_covered_list) + badges_earned_json = json.dumps(badges_earned_list) + language_used_json = json.dumps(language_used_list) + + data_set = { + "LeetCodeUsername": username, + "CandidateName": candidate_name, + "CandidateRank": candidate_rank, + "ContestAttended": contest_attended, + "ContestRating": contest_rating, + "ContestGlobalRanking": contest_global_ranking, + "TotalProblemsSolved": total_problem_solved, + "EasyProblem": problems_solved[0].text, + "MediumProblem": problems_solved[1].text, + "HardProblem": problems_solved[2].text, + # "TotalSubmissions": total_submissions, + # "TotalActiveDays": total_active_days, + # "MaxStreak": max_streak, + "MostRecentlyEarnedBadge": most_recent_badge, + "Last15SolvedProblems": solved_problem_json, + "TopicsCovered": topics_covered_json, + "BadgesEarned": badges_earned_json, + "LanguageUsed": language_used_json, + # "LastSolved": last_solved, + } + + json_dump = json.dumps(data_set) + return json_dump + + +if __name__ == "__main__": + app.run() From 99aa7c0e46f4a48ae80e44127e7720642ebb5bda Mon Sep 17 00:00:00 2001 From: jayadhar gandham <42913445+JayadharGj@users.noreply.github.com> Date: Fri, 2 Feb 2024 22:49:14 -0500 Subject: [PATCH 2/6] Create Leetrequirements.txt requirements file for leetcode txt --- Leetrequirements.txt | Bin 0 -> 417 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Leetrequirements.txt diff --git a/Leetrequirements.txt b/Leetrequirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..457b5a20fc4386d7256713c3ba3d2f1273602a34 GIT binary patch literal 417 zcmYk2OK!qI5JYS3yI{e95LvK_ltrYhIDvs7f*6MwgOc0xss}_gns0r&de+KnbkU%_ zcI>Ur`er|ArX^#hS`#JKq)Hp`J?mFsi@<74LEbVJ~#jX literal 0 HcmV?d00001 From a393e1131c58a384bc59e1f1e9f602ff3824e17c Mon Sep 17 00:00:00 2001 From: jayadhar gandham <42913445+JayadharGj@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:15:03 -0500 Subject: [PATCH 3/6] Update Leetrequirements.txt url_quote error --- Leetrequirements.txt | Bin 417 -> 433 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Leetrequirements.txt b/Leetrequirements.txt index 457b5a20fc4386d7256713c3ba3d2f1273602a34..c4da3efa7454d02e9c4c27ab21e0fecd27af5d70 100644 GIT binary patch delta 26 gcmZ3;ypegsd`6-0)S~RF)Y5cYTO&On Date: Sat, 3 Feb 2024 12:16:02 -0500 Subject: [PATCH 4/6] Update leetcode.py error handled for index out of bounds --- leetcode.py | 264 +++++++++++++++++++++++++--------------------------- 1 file changed, 127 insertions(+), 137 deletions(-) diff --git a/leetcode.py b/leetcode.py index 57f475e..8d544eb 100644 --- a/leetcode.py +++ b/leetcode.py @@ -7,150 +7,140 @@ app = Flask(__name__) CORS(app) +# remove unnecessary find_all and find methods and use try-except block to handle the error @app.route("/", methods=["GET"]) # creating an endpoint for GET request def home_page(): return "

Hello, Welcome to LEETCODE SCRAPPER's HOMEPAGE

To get someone's LeetCode Account Details send GET request to the below URL

https://subrata-rudra-leetcode-scrapper.onrender.com/user/?user=LEETCODE_USERNAME_OF_USER

" - @app.route("/user/", methods=["GET"]) def request_data(): - username = str(request.args.get("user")) - - base_url = "https://leetcode.com/" - - final_url = base_url + username - - html_text = requests.get(final_url).text - - soup = BeautifulSoup(html_text, "lxml") - - username = soup.find( - "div", class_="text-label-3 dark:text-dark-label-3 text-xs" - ).text - - candidate_name = soup.find( - "div", - class_="text-label-1 dark:text-dark-label-1 break-all text-base font-semibold", - ).text - - candidate_rank = soup.find( - "span", class_="ttext-label-1 dark:text-dark-label-1 font-medium" - ).text - - contest_attended = soup.find_all( - "div", class_="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]" - )[1].text - - contest_rating = soup.find( - "div", class_="text-label-1 dark:text-dark-label-1 flex items-center text-2xl" - ).text - - contest_global_ranking = soup.find( - "div", class_="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]" - ).text - - total_problem_solved = soup.find( - "div", class_="text-[24px] font-medium text-label-1 dark:text-dark-label-1" - ).text - - problems_solved = soup.find_all( - "span", - class_="mr-[5px] text-base font-medium leading-[20px] text-label-1 dark:text-dark-label-1", - ) - - # total_submissions = soup.find( - # "span", class_="mr-[5px] text-base font-medium lc-md:text-xl" - # ).text - - language_used = soup.find_all( - "span", - class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full text-label-3 dark:text-dark-label-3 bg-fill-3 dark:bg-dark-fill-3 notranslate", - ) - - # total_active_days = soup.find_all( - # "span", class_="font-medium text-label-2 dark:text-dark-label-2" - # )[3].text - - # max_streak = soup.find_all( - # "span", class_="font-medium text-label-2 dark:text-dark-label-2" - # )[4].text - - solved_problem = soup.find_all( - "span", class_="text-label-1 dark:text-dark-label-1 font-medium line-clamp-1" - ) - - topics_covered = soup.find_all( - "span", - class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full bg-fill-3 dark:bg-dark-fill-3 cursor-pointer transition-all hover:bg-fill-2 dark:hover:bg-dark-fill-2 text-label-2 dark:text-dark-label-2", - ) - - badges_earned = soup.find_all( - "img", class_="h-full w-full cursor-pointer object-contain" - ) - - most_recent_badge = soup.find( - "div", class_="text-label-1 dark:text-dark-label-1 text-base" - ).text - - # last_solved = soup.find( - # "span", - # class_="text-label-3 dark:text-dark-label-3 hidden whitespace-nowrap lc-md:inline", - # ).text - - language_used_list = [] - ind = 0 - for language in language_used: - language_used_list.insert(ind, language.text) - ind = ind + 1 - - solved_problem_list = [] - ind = 0 - for problem in solved_problem: - solved_problem_list.insert(ind, problem.text) - ind = ind + 1 - - topics_covered_list = [] - ind = 0 - for topic in topics_covered: - topics_covered_list.insert(ind, topic.text) - ind = ind + 1 - - badges_earned_list = [] - ind = 0 - for badge in badges_earned: - badges_earned_list.insert(ind, badge["alt"]) - ind = ind + 1 - - solved_problem_json = json.dumps(solved_problem_list) - topics_covered_json = json.dumps(topics_covered_list) - badges_earned_json = json.dumps(badges_earned_list) - language_used_json = json.dumps(language_used_list) - - data_set = { - "LeetCodeUsername": username, - "CandidateName": candidate_name, - "CandidateRank": candidate_rank, - "ContestAttended": contest_attended, - "ContestRating": contest_rating, - "ContestGlobalRanking": contest_global_ranking, - "TotalProblemsSolved": total_problem_solved, - "EasyProblem": problems_solved[0].text, - "MediumProblem": problems_solved[1].text, - "HardProblem": problems_solved[2].text, - # "TotalSubmissions": total_submissions, - # "TotalActiveDays": total_active_days, - # "MaxStreak": max_streak, - "MostRecentlyEarnedBadge": most_recent_badge, - "Last15SolvedProblems": solved_problem_json, - "TopicsCovered": topics_covered_json, - "BadgesEarned": badges_earned_json, - "LanguageUsed": language_used_json, - # "LastSolved": last_solved, - } - - json_dump = json.dumps(data_set) - return json_dump + try: + username = str(request.args.get("user")) + print(username) + base_url = "https://leetcode.com/" + + final_url = base_url + username + + html_text = requests.get(final_url).text + + soup = BeautifulSoup(html_text, "lxml") + + username = get_value(soup, "div", "text-label-3 dark:text-dark-label-3 text-xs") + + candidate_name = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 break-all text-base font-semibold", + ) + + candidate_rank = get_value( + soup, "span", "ttext-label-1 dark:text-dark-label-1 font-medium" + ) + + contest_attended = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 font-medium leading-[22px]", + index=1, + ) + + contest_rating = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 flex items-center text-2xl", + ) + + contest_global_ranking = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 font-medium leading-[22px]", + ) + + total_problem_solved = get_value( + soup, + "div", + "text-[24px] font-medium text-label-1 dark:text-dark-label-1", + ) + + problems_solved = soup.find_all( + "span", + class_="mr-[5px] text-base font-medium leading-[20px] text-label-1 dark:text-dark-label-1", + ) + + language_used = soup.find_all( + "span", + class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full text-label-3 dark:text-dark-label-3 bg-fill-3 dark:bg-dark-fill-3 notranslate", + ) + + solved_problem = soup.find_all( + "span", class_="text-label-1 dark:text-dark-label-1 font-medium line-clamp-1" + ) + + topics_covered = soup.find_all( + "span", + class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full bg-fill-3 dark:bg-dark-fill-3 cursor-pointer transition-all hover:bg-fill-2 dark:hover:bg-dark-fill-2 text-label-2 dark:text-dark-label-2", + ) + + badges_earned = soup.find_all( + "img", class_="h-full w-full cursor-pointer object-contain" + ) + + most_recent_badge = get_value( + soup, "div", "text-label-1 dark:text-dark-label-1 text-base" + ) + + language_used_list = [language.text for language in language_used] + + solved_problem_list = [problem.text for problem in solved_problem] + + topics_covered_list = [topic.text for topic in topics_covered] + + badges_earned_list = [badge["alt"] for badge in badges_earned] + + solved_problem_json = json.dumps(solved_problem_list) + topics_covered_json = json.dumps(topics_covered_list) + badges_earned_json = json.dumps(badges_earned_list) + language_used_json = json.dumps(language_used_list) + + data_set = { + "LeetCodeUsername": username, + "CandidateName": candidate_name, + "CandidateRank": candidate_rank, + "ContestAttended": contest_attended, + "ContestRating": contest_rating, + "ContestGlobalRanking": contest_global_ranking, + "TotalProblemsSolved": total_problem_solved, + "EasyProblem": get_list_value(problems_solved, 0), + "MediumProblem": get_list_value(problems_solved, 1), + "HardProblem": get_list_value(problems_solved, 2), + "MostRecentlyEarnedBadge": most_recent_badge, + "Last15SolvedProblems": solved_problem_json, + "TopicsCovered": topics_covered_json, + "BadgesEarned": badges_earned_json, + "LanguageUsed": language_used_json, + } + + json_dump = json.dumps(data_set) + return json_dump + + except Exception as e: + error_message = f"Error: {str(e)}" + return json.dumps({"error": error_message}) + + +def get_value(soup, tag, class_name, index=0): + try: + return soup.find(tag, class_=class_name).text + except (AttributeError, IndexError): + return None + + +def get_list_value(lst, index): + try: + return lst[index].text + except (IndexError, AttributeError): + return None if __name__ == "__main__": From 402c7e2d5e0f48acc2bdc32d8da69ddf4a6b7608 Mon Sep 17 00:00:00 2001 From: jayadhar gandham <42913445+JayadharGj@users.noreply.github.com> Date: Fri, 23 Feb 2024 00:03:38 +0000 Subject: [PATCH 5/6] Leetcode scrape endpoint --- leetcode.py | 147 ---------------------------------------------------- main.py | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 147 deletions(-) delete mode 100644 leetcode.py diff --git a/leetcode.py b/leetcode.py deleted file mode 100644 index 8d544eb..0000000 --- a/leetcode.py +++ /dev/null @@ -1,147 +0,0 @@ -from bs4 import BeautifulSoup -import requests -from flask import * -import json -from flask_cors import CORS - -app = Flask(__name__) -CORS(app) - -# remove unnecessary find_all and find methods and use try-except block to handle the error - -@app.route("/", methods=["GET"]) # creating an endpoint for GET request -def home_page(): - return "

Hello, Welcome to LEETCODE SCRAPPER's HOMEPAGE

To get someone's LeetCode Account Details send GET request to the below URL

https://subrata-rudra-leetcode-scrapper.onrender.com/user/?user=LEETCODE_USERNAME_OF_USER

" - -@app.route("/user/", methods=["GET"]) -def request_data(): - try: - username = str(request.args.get("user")) - print(username) - base_url = "https://leetcode.com/" - - final_url = base_url + username - - html_text = requests.get(final_url).text - - soup = BeautifulSoup(html_text, "lxml") - - username = get_value(soup, "div", "text-label-3 dark:text-dark-label-3 text-xs") - - candidate_name = get_value( - soup, - "div", - "text-label-1 dark:text-dark-label-1 break-all text-base font-semibold", - ) - - candidate_rank = get_value( - soup, "span", "ttext-label-1 dark:text-dark-label-1 font-medium" - ) - - contest_attended = get_value( - soup, - "div", - "text-label-1 dark:text-dark-label-1 font-medium leading-[22px]", - index=1, - ) - - contest_rating = get_value( - soup, - "div", - "text-label-1 dark:text-dark-label-1 flex items-center text-2xl", - ) - - contest_global_ranking = get_value( - soup, - "div", - "text-label-1 dark:text-dark-label-1 font-medium leading-[22px]", - ) - - total_problem_solved = get_value( - soup, - "div", - "text-[24px] font-medium text-label-1 dark:text-dark-label-1", - ) - - problems_solved = soup.find_all( - "span", - class_="mr-[5px] text-base font-medium leading-[20px] text-label-1 dark:text-dark-label-1", - ) - - language_used = soup.find_all( - "span", - class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full text-label-3 dark:text-dark-label-3 bg-fill-3 dark:bg-dark-fill-3 notranslate", - ) - - solved_problem = soup.find_all( - "span", class_="text-label-1 dark:text-dark-label-1 font-medium line-clamp-1" - ) - - topics_covered = soup.find_all( - "span", - class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full bg-fill-3 dark:bg-dark-fill-3 cursor-pointer transition-all hover:bg-fill-2 dark:hover:bg-dark-fill-2 text-label-2 dark:text-dark-label-2", - ) - - badges_earned = soup.find_all( - "img", class_="h-full w-full cursor-pointer object-contain" - ) - - most_recent_badge = get_value( - soup, "div", "text-label-1 dark:text-dark-label-1 text-base" - ) - - language_used_list = [language.text for language in language_used] - - solved_problem_list = [problem.text for problem in solved_problem] - - topics_covered_list = [topic.text for topic in topics_covered] - - badges_earned_list = [badge["alt"] for badge in badges_earned] - - solved_problem_json = json.dumps(solved_problem_list) - topics_covered_json = json.dumps(topics_covered_list) - badges_earned_json = json.dumps(badges_earned_list) - language_used_json = json.dumps(language_used_list) - - data_set = { - "LeetCodeUsername": username, - "CandidateName": candidate_name, - "CandidateRank": candidate_rank, - "ContestAttended": contest_attended, - "ContestRating": contest_rating, - "ContestGlobalRanking": contest_global_ranking, - "TotalProblemsSolved": total_problem_solved, - "EasyProblem": get_list_value(problems_solved, 0), - "MediumProblem": get_list_value(problems_solved, 1), - "HardProblem": get_list_value(problems_solved, 2), - "MostRecentlyEarnedBadge": most_recent_badge, - "Last15SolvedProblems": solved_problem_json, - "TopicsCovered": topics_covered_json, - "BadgesEarned": badges_earned_json, - "LanguageUsed": language_used_json, - } - - json_dump = json.dumps(data_set) - return json_dump - - except Exception as e: - error_message = f"Error: {str(e)}" - return json.dumps({"error": error_message}) - - -def get_value(soup, tag, class_name, index=0): - try: - return soup.find(tag, class_=class_name).text - except (AttributeError, IndexError): - return None - - -def get_list_value(lst, index): - try: - return lst[index].text - except (IndexError, AttributeError): - return None - - -if __name__ == "__main__": - app.run() diff --git a/main.py b/main.py index 76a69c0..a029a71 100644 --- a/main.py +++ b/main.py @@ -3,11 +3,13 @@ from flask import Flask, jsonify, request from linkedin_api import Linkedin from huggingface_hub import InferenceClient +from flask_cors import CORS client = InferenceClient( "mistralai/Mistral-7B-Instruct-v0.1" ) app = Flask(__name__) +CORS(app) linkedin = Linkedin("snehithb295@gmail.com", "Test@476") @@ -135,6 +137,134 @@ def scrape_github_profiles(): else: return None +@app.route('/scrape_leetcode_profiles/user/',methods = ['GET']) +def scrape_leetcode_profile(): + try: + username = str(request.args.get("user")) + print(username) + base_url = "https://leetcode.com/" + + final_url = base_url + username + + html_text = requests.get(final_url).text + + soup = BeautifulSoup(html_text, "lxml") + + username = get_value(soup, "div", "text-label-3 dark:text-dark-label-3 text-xs") + + candidate_name = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 break-all text-base font-semibold", + ) + + candidate_rank = get_value( + soup, "span", "ttext-label-1 dark:text-dark-label-1 font-medium" + ) + + contest_attended = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 font-medium leading-[22px]", + index=1, + ) + + contest_rating = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 flex items-center text-2xl", + ) + + contest_global_ranking = get_value( + soup, + "div", + "text-label-1 dark:text-dark-label-1 font-medium leading-[22px]", + ) + + total_problem_solved = get_value( + soup, + "div", + "text-[24px] font-medium text-label-1 dark:text-dark-label-1", + ) + + problems_solved = soup.find_all( + "span", + class_="mr-[5px] text-base font-medium leading-[20px] text-label-1 dark:text-dark-label-1", + ) + + language_used = soup.find_all( + "span", + class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full text-label-3 dark:text-dark-label-3 bg-fill-3 dark:bg-dark-fill-3 notranslate", + ) + + solved_problem = soup.find_all( + "span", class_="text-label-1 dark:text-dark-label-1 font-medium line-clamp-1" + ) + + topics_covered = soup.find_all( + "span", + class_="inline-flex items-center px-2 whitespace-nowrap text-xs leading-6 rounded-full bg-fill-3 dark:bg-dark-fill-3 cursor-pointer transition-all hover:bg-fill-2 dark:hover:bg-dark-fill-2 text-label-2 dark:text-dark-label-2", + ) + + badges_earned = soup.find_all( + "img", class_="h-full w-full cursor-pointer object-contain" + ) + + most_recent_badge = get_value( + soup, "div", "text-label-1 dark:text-dark-label-1 text-base" + ) + + language_used_list = [language.text for language in language_used] + + solved_problem_list = [problem.text for problem in solved_problem] + + topics_covered_list = [topic.text for topic in topics_covered] + + badges_earned_list = [badge["alt"] for badge in badges_earned] + + solved_problem_json = json.dumps(solved_problem_list) + topics_covered_json = json.dumps(topics_covered_list) + badges_earned_json = json.dumps(badges_earned_list) + language_used_json = json.dumps(language_used_list) + + data_set = { + "LeetCodeUsername": username, + "CandidateName": candidate_name, + "CandidateRank": candidate_rank, + "ContestAttended": contest_attended, + "ContestRating": contest_rating, + "ContestGlobalRanking": contest_global_ranking, + "TotalProblemsSolved": total_problem_solved, + "EasyProblem": get_list_value(problems_solved, 0), + "MediumProblem": get_list_value(problems_solved, 1), + "HardProblem": get_list_value(problems_solved, 2), + "MostRecentlyEarnedBadge": most_recent_badge, + "Last15SolvedProblems": solved_problem_json, + "TopicsCovered": topics_covered_json, + "BadgesEarned": badges_earned_json, + "LanguageUsed": language_used_json, + } + + json_dump = json.dumps(data_set) + return json_dump + + except Exception as e: + error_message = f"Error: {str(e)}" + return json.dumps({"error": error_message}) + + +def get_value(soup, tag, class_name, index=0): + try: + return soup.find(tag, class_=class_name).text + except (AttributeError, IndexError): + return None + + +def get_list_value(lst, index): + try: + return lst[index].text + except (IndexError, AttributeError): + return None @app.route('/scrape_medium_profiles', methods=['POST']) def scrape_medium_profiles(): From 890454b2e91c92ea617ac4a9dc810cddf297e63b Mon Sep 17 00:00:00 2001 From: jayadhar gandham <42913445+JayadharGj@users.noreply.github.com> Date: Fri, 23 Feb 2024 00:13:06 +0000 Subject: [PATCH 6/6] Leetcode scrape endpoint --- Leetrequirements.txt | Bin 433 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Leetrequirements.txt diff --git a/Leetrequirements.txt b/Leetrequirements.txt deleted file mode 100644 index c4da3efa7454d02e9c4c27ab21e0fecd27af5d70..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 433 zcmYk2OHaZ;6ot>a|AhtyLUhrUi3<}~E?gHJ2vRE6Vw7LcckVzmlX;%UJ$F{hYIV}6 zoi^;9zVyL<)Itqop;|K~)}%^n@Ez+uu)Dx&%|RYPTC@cz{G$0oCVIeofMw@7>S;Jk z(Qm2QhqoDhFwzw_uL3)e%IFv=R+{jVxwU#@dbjTqPtT$msb;jNLPqP}N_}UXG2Pb_ z?!DgOrSNdJ8`kNEI$gZ`H}0>RXV?S%`mbI%Z}4~h|Go$Pf*ct}O1Cw6vc4nV!08i* aOeQD2>684oBzw)n{+v(Srb#uUQgs3C#zO)C