From f461b72513fe92a0cd211093bd35449a180e4b46 Mon Sep 17 00:00:00 2001 From: Agastya Kumar Yadav Date: Fri, 31 May 2024 03:00:29 +0000 Subject: [PATCH 1/5] added mlh.py --- src/scrape_up/mlh/mlh.py | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/scrape_up/mlh/mlh.py diff --git a/src/scrape_up/mlh/mlh.py b/src/scrape_up/mlh/mlh.py new file mode 100644 index 00000000..6ab7272a --- /dev/null +++ b/src/scrape_up/mlh/mlh.py @@ -0,0 +1,114 @@ +from bs4 import BeautifulSoup +from scrape_up.config.request_config import RequestConfig, get + +class MLH: + """ + Create an instance of the class `GeeksforGeeks` + ```py + mlh = MLH() + mlh.get_events() + ``` + + | Methods | Details | + | ----------------- | ---------------------------------------------------------------------------------- | + | `.get_events()` | Returns the upcoming event ,past event,ongoing event. | + + """ + def __init__(self, user: str, *, config: RequestConfig = RequestConfig()): + headers = {"User-Agent": "scrapeup"} + self.config = config + if self.config.headers == {}: + self.config.set_headers(headers) + def get_events(self): + try: + url = "https://mlh.io/seasons/2024/events" + response = get(url, self.config) + soup = BeautifulSoup(response.text, "html.parser") + main_info=soup.find_all('div',class_="container feature") + events=main_info[1] + types=events.find_all('div',class_='row') + e=[] + for t in types: + h=t.find('h3',class_='text-center mb-3') + print(h) + + if(h): + d=[] + evs=t.find_all('div',class_='event') + print(len(evs)) + for ev in evs: + name=ev.find('h3',class_='event-name').text.strip() + date=ev.find('p',class_='event-date').text.strip() + location=ev.find('div',class_='event-location').text.strip().replace('\n'," ").replace(' '," ") + mode=ev.find('div',class_='event-hybrid-notes').text.strip() + d.append({'name':name,'location':location,'date':date,'mode':mode}) + e.append({h.text.strip():d}) + + return (json.dumps(e)) + except Exception as e: + return None + + +""" + response example: + + [ + { + "Upcoming Events": [ + { + "name": "Global Hack Week: Web3", + "location": "Everywhere, Online", + "date": "Jun 7th - 13th", + "mode": "Digital Only" + }, + { + "name": "JAMHacks 8", + "location": "Waterloo, Ontario", + "date": "Jun 7th - 9th", + "mode": "In-Person Only" + }, + { + "name": "Hack Your Portfolio", + "location": "Everywhere, Worldwide", + "date": "Jun 14th - 16th", + "mode": "Digital Only" + } + ] + }, + { + "Past Events": [ + { + "name": "TechTogether Online", + "location": "Everywhere, Worldwide", + "date": "Jul 14th - 16th", + "mode": "Digital Only" + }, + { + "name": "Hacks for Hackers", + "location": "Everywhere, Worldwide", + "date": "Jul 21st - 23rd", + "mode": "Digital Only" + }, + { + "name": "HackBattle: React vs Angular", + "location": "Everywhere, Worldwide", + "date": "Jul 28th - 30th", + "mode": "Digital Only" + }, + { + "name": "Global Hack Week: Data", + "location": "Everywhere, Worldwide", + "date": "Jul 31st - Aug 7th", + "mode": "Digital Only" + }, + { + "name": "TechTogether Online", + "location": "Everywhere, Worldwide", + "date": "Aug 4th - 6th", + "mode": "Digital Only" + } + ] + } +] +""" + \ No newline at end of file From 529555df085cf7451a9f64bc8cabd5a8e69d4792 Mon Sep 17 00:00:00 2001 From: Agastya Kumar Yadav Date: Fri, 31 May 2024 03:03:54 +0000 Subject: [PATCH 2/5] added main file --- src/scrape_up/mlh/__init__.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/scrape_up/mlh/__init__.py diff --git a/src/scrape_up/mlh/__init__.py b/src/scrape_up/mlh/__init__.py new file mode 100644 index 00000000..22bbe0dd --- /dev/null +++ b/src/scrape_up/mlh/__init__.py @@ -0,0 +1,3 @@ +from .mlh import MLH + +__all__ = ["MLH"] From 19c26f5817c3efef7d64fa92a1e15e0d9181e246 Mon Sep 17 00:00:00 2001 From: Agastya Kumar Yadav Date: Fri, 31 May 2024 03:06:43 +0000 Subject: [PATCH 3/5] added documentation --- dev-documentation.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dev-documentation.md b/dev-documentation.md index 0a30421f..884bde9a 100644 --- a/dev-documentation.md +++ b/dev-documentation.md @@ -2007,7 +2007,7 @@ Class - `Lastfm` | `.get_followers()` | Returns the total number of followers of the user. | Note: usernames are case sensitive. - +--- #### CodeWars ```python @@ -2020,3 +2020,16 @@ cwars.get_profile() | `.get_profile()` | Returns the user data in json format. | --- + +#### MLH + Create an instance of the class `GeeksforGeeks` + ```py + mlh = MLH() + mlh.get_events() + ``` + + | Methods | Details | + | ----------------- | ---------------------------------------------------------------------------------- | + | `.get_events()` | Returns the upcoming event ,past event,ongoing event. | + +--- From 29b35a6954000a7b123de0bca36fb1eff846e0c5 Mon Sep 17 00:00:00 2001 From: Agastya Kumar Yadav <124435030+agastya3636@users.noreply.github.com> Date: Sun, 2 Jun 2024 00:17:58 +0530 Subject: [PATCH 4/5] fixed url and removed print statement --- dev-documentation.md | 2 +- src/scrape_up/mlh/mlh.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dev-documentation.md b/dev-documentation.md index 884bde9a..9641521f 100644 --- a/dev-documentation.md +++ b/dev-documentation.md @@ -2024,7 +2024,7 @@ cwars.get_profile() #### MLH Create an instance of the class `GeeksforGeeks` ```py - mlh = MLH() + mlh = MLH(year="2024") mlh.get_events() ``` diff --git a/src/scrape_up/mlh/mlh.py b/src/scrape_up/mlh/mlh.py index 6ab7272a..7606c240 100644 --- a/src/scrape_up/mlh/mlh.py +++ b/src/scrape_up/mlh/mlh.py @@ -1,11 +1,11 @@ from bs4 import BeautifulSoup from scrape_up.config.request_config import RequestConfig, get - +import json class MLH: """ Create an instance of the class `GeeksforGeeks` ```py - mlh = MLH() + mlh = MLH(year="2024") mlh.get_events() ``` @@ -14,14 +14,15 @@ class MLH: | `.get_events()` | Returns the upcoming event ,past event,ongoing event. | """ - def __init__(self, user: str, *, config: RequestConfig = RequestConfig()): + def __init__(self, year: str, *, config: RequestConfig = RequestConfig()): headers = {"User-Agent": "scrapeup"} self.config = config + self.year= year if self.config.headers == {}: self.config.set_headers(headers) def get_events(self): try: - url = "https://mlh.io/seasons/2024/events" + url = f"https://mlh.io/seasons/{self.year}/events" response = get(url, self.config) soup = BeautifulSoup(response.text, "html.parser") main_info=soup.find_all('div',class_="container feature") @@ -30,12 +31,10 @@ def get_events(self): e=[] for t in types: h=t.find('h3',class_='text-center mb-3') - print(h) if(h): d=[] evs=t.find_all('div',class_='event') - print(len(evs)) for ev in evs: name=ev.find('h3',class_='event-name').text.strip() date=ev.find('p',class_='event-date').text.strip() From 839965a07cf1937e70c76d3725669514f7916806 Mon Sep 17 00:00:00 2001 From: Agastya Kumar Yadav <124435030+agastya3636@users.noreply.github.com> Date: Sun, 2 Jun 2024 00:22:00 +0530 Subject: [PATCH 5/5] Fixed documentation --- dev-documentation.md | 2 +- src/scrape_up/mlh/mlh.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dev-documentation.md b/dev-documentation.md index 9641521f..34d83223 100644 --- a/dev-documentation.md +++ b/dev-documentation.md @@ -2022,7 +2022,7 @@ cwars.get_profile() --- #### MLH - Create an instance of the class `GeeksforGeeks` + Create an instance of the class `MLH` ```py mlh = MLH(year="2024") mlh.get_events() diff --git a/src/scrape_up/mlh/mlh.py b/src/scrape_up/mlh/mlh.py index 7606c240..481101a6 100644 --- a/src/scrape_up/mlh/mlh.py +++ b/src/scrape_up/mlh/mlh.py @@ -3,7 +3,7 @@ import json class MLH: """ - Create an instance of the class `GeeksforGeeks` + Create an instance of the class `MLH` ```py mlh = MLH(year="2024") mlh.get_events() @@ -43,7 +43,7 @@ def get_events(self): d.append({'name':name,'location':location,'date':date,'mode':mode}) e.append({h.text.strip():d}) - return (json.dumps(e)) + return (json.dumps(e, indent=2)) except Exception as e: return None