Skip to content

Commit

Permalink
sisters in sweat.
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Jul 16, 2024
1 parent 76cb9ed commit 063dd57
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1,418 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ out/aceofpubs.json: out/aceofpubs.ics
out/koota.txt:
curl_chrome116 --silent "https://courtyardkoota.com/event-directory/" | grep -oE 'https://courtyardkoota\.com/events/[a-z0-9-]+/' | sort -u > $@ || $(call restore-file,$@)

# TODO
# out/sis.txt:
# python src/sis.py | sort > out/sis.txt
out/sis.json:
python src/sis.py || $(call restore-file,$@)

fetch: out/allevents.txt \
out/highape.txt \
Expand Down Expand Up @@ -166,7 +165,8 @@ fetch: out/allevents.txt \
out/atta_galatta.json \
out/koota.txt \
out/te.json \
out/underline.json
out/underline.json \
out/sis.json

@echo "Done"

Expand Down
815 changes: 0 additions & 815 deletions fixtures/sisters-in-sweat-event.html

This file was deleted.

580 changes: 0 additions & 580 deletions fixtures/sisters-in-sweat.html

This file was deleted.

36 changes: 36 additions & 0 deletions out/sis.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/event-fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"out/venn.json", # this also has a lot of duplicates
"out/te.json",
"out/zomato.json",
"out/underline.json" # duplicates to insider
"out/underline.json", # duplicates to insider
"out/sis.json"
]

KNOWN_EVENT_TYPES = [
Expand Down
1 change: 0 additions & 1 deletion src/gullytours.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ def read_config():


if __name__ == "__main__":

main()
95 changes: 78 additions & 17 deletions src/sis.py
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)

0 comments on commit 063dd57

Please sign in to comment.