-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
1,418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,5 +92,4 @@ def read_config(): | |
|
||
|
||
if __name__ == "__main__": | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,99 @@ | ||
from bs4 import BeautifulSoup | ||
from common.session import get_cached_session | ||
# from common.session import get_cached_session | ||
import requests | ||
from common.tz import IST | ||
import json | ||
import datetime | ||
import re | ||
import os | ||
from urllib.parse import urlencode | ||
import datefinder | ||
BASE_URL = "https://sistersinsweat.in" | ||
|
||
|
||
def fetch_events_html(): | ||
session = get_cached_session() | ||
response = session.get("https://sistersinsweat.in/events?city=4") | ||
def fetch_events_html(session): | ||
response = session.get(BASE_URL + "/events?city=4") | ||
return response.text | ||
|
||
def fix_date(date_str): | ||
return date_str.replace(" ", "T") + "+05:30" | ||
|
||
def fetch_ajax_details(sku, _token): | ||
data = { | ||
"_token": _token, | ||
"sku": sku, | ||
"location_name": "4" | ||
} | ||
url = BASE_URL + "/getTimeSlotAjax" | ||
e = session.post(url, data=data).json()[0] | ||
|
||
return { | ||
"startDate": fix_date(e['start_date']), | ||
"endDate": fix_date(e['end_date']), | ||
"offers": [{ | ||
"price": e['price'], | ||
"priceCurrency": "INR" | ||
}] | ||
} | ||
|
||
def read_events_html(): | ||
with open("fixtures/sisters-in-sweat.html", "r") as f: | ||
return f.read() | ||
|
||
def fetch_event_details(session, l): | ||
|
||
def fetch_event_details(l): | ||
session = get_cached_session() | ||
response = session.get(l) | ||
html = response.text | ||
soup = BeautifulSoup(html, "html.parser") | ||
div = soup.select_one("#description").text.replace("\n\n", "\n") | ||
print(div) | ||
|
||
div = soup.select_one("#description") | ||
event = { | ||
"name": soup.select_one('h2').text, | ||
"@type": "SocialEvent", | ||
"url": l, | ||
"@context": "https://schema.org", | ||
"keywords": ["SISTERSINSWEAT"], | ||
"audience": { | ||
"@type": "Audience", | ||
"AudienceType": "Women-only event" | ||
}, | ||
"eventAttendanceMode": "OfflineEventAttendanceMode", | ||
"eventStatus": "EventScheduled", | ||
"inLanguage": "en", | ||
"organizer": { | ||
"@type": "Organization", | ||
"name": "Sisters In Sweat", | ||
"url": "https://sistersinsweat.in" | ||
} | ||
} | ||
if div: | ||
text = div.text.replace("\n\n", "\n") | ||
event['description'] = text | ||
img = soup.select_one('img.img-fluid') | ||
if img: | ||
event['image'] = img.get('src') | ||
v = soup.select_one('#venue') | ||
if v: | ||
venue_text = v.text | ||
s = venue_text.split("-") | ||
venue_text = s[0].strip() | ||
venue_address = " ".join(s[1:]) | ||
event['location'] = { | ||
"name": venue_text, | ||
"address": venue_address, | ||
"type": "Place" | ||
} | ||
sku = soup.select_one('input[name="sku"]').get('value') | ||
_token = soup.select_one('input[name="_token"]').get('value') | ||
event = event | fetch_ajax_details(sku, _token) | ||
return event | ||
|
||
def fetch_events_links(html): | ||
soup = BeautifulSoup(html, "html.parser") | ||
links = soup.select('a[href^="https://sistersinsweat.in/session_details/"]') | ||
return [link.get("href") for link in links] | ||
|
||
|
||
html = read_events_html() | ||
for l in fetch_events_links(html): | ||
fetch_event_details(l) | ||
if __name__ == "__main__": | ||
session = requests.Session() # get_cached_session() | ||
html = fetch_events_html(session) | ||
events = [] | ||
for l in fetch_events_links(html): | ||
e = fetch_event_details(session, l) | ||
events.append(e) | ||
with open("out/sis.json", "w") as f: | ||
json.dump(events, f, indent=2) |