Skip to content

Commit

Permalink
Adds Sofar
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Mar 31, 2024
1 parent ee73b60 commit c5a4612
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 21 deletions.
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,25 @@ out/zomato.json:
out/bic.json:
python src/ics-to-event.py out/bic.ics out/bic.json

all: out/allevents.txt out/highape.txt out/mapindia.json out/bic.ics out/insider.txt out/bengalurusustainabilityforum.json out/bhaagoindia.txt out/scigalleryblr.json out/mmb.txt out/venn.json out/zomato.json out/urbanaut.json out/champaca.json out/atta_galatta.json out/bic.json
out/sofar.json:
python src/sofar.py

all: out/allevents.txt \
out/highape.txt \
out/mapindia.json \
out/bic.ics \
out/insider.txt \
out/bengalurusustainabilityforum.json \
out/bhaagoindia.txt \
out/scigalleryblr.json \
out/mmb.txt \
out/venn.json \
out/zomato.json \
out/urbanaut.json \
out/champaca.json \
out/atta_galatta.json \
out/bic.json \
out/sofar.json
@echo "Done"

db:
Expand Down
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

We either have URLs that can be easily scraped (https://schema.org/Event), or a file with enough details to recreate it.

| Source | Scraped | Parsed | In Database | Notes |
|:-------------------------------|:--------|:-------|:------------|:-------|
| AllEvents.in | ✔️ | ✔️ | ✔️ | |
| HighApe.com | ✔️ | ✔️ | ✔️ | |
| map-india.org | ✔️ | ✔️ || |
| BIC | ✔️ | ✔️ | ✔️ | Converted from ICS Calendar |
| Paytm Insider | ✔️ | ✔️ | ✔️ | |
| Bengaluru Sustainability Forum | ✔️ | ✔️ || |
| Bhaago India | ✔️ | ✔️ | ✔️ | |
| Carbon Science Gallery | ✔️ | ✔️ || |
| Max Mueller Bhavan | ✔️ | ✔️ | ✔️ | |
| https://events.venn.buzz/ | ✔️ | ✔️ || |
| https://linktr.ee/atta_galatta | ✔️ | ✔️ || |
| Zomato | ✔️ | ✔️ || |
| Champaca | ✔️ | ✔️ || |
| [Visvesvaraya Museum][vism]. |||| OCR |
| [NGMA][ngma] |||| OCR The [older website calender](http://www.ngmaindia.gov.in/ngma_bangaluru_calendar.asp) is not updated.|
| Source | Scraped | Parsed | In Database | Notes |
|:-------------------------------|:--------|:-------|:------------|:----------------------------------------------------------------------------------------------------------|
| AllEvents.in | ✔️ | ✔️ | ✔️ | |
| HighApe.com | ✔️ | ✔️ | ✔️ | |
| map-india.org | ✔️ | ✔️ || |
| BIC | ✔️ | ✔️ | ✔️ | Converted from ICS Calendar |
| Paytm Insider | ✔️ | ✔️ | ✔️ | |
| Bengaluru Sustainability Forum | ✔️ | ✔️ || |
| Bhaago India | ✔️ | ✔️ | ✔️ | |
| Carbon Science Gallery | ✔️ | ✔️ || |
| Max Mueller Bhavan | ✔️ | ✔️ | ✔️ | |
| https://events.venn.buzz/ | ✔️ | ✔️ || |
| https://linktr.ee/atta_galatta | ✔️ | ✔️ || |
| Zomato | ✔️ | ✔️ || |
| Champaca | ✔️ | ✔️ || |
| [Visvesvaraya Museum][vism]. |||| OCR |
| [NGMA][ngma] |||| OCR The [older website calender](http://www.ngmaindia.gov.in/ngma_bangaluru_calendar.asp) is not updated. |
| [Sofar][sofar] | ✔️ | ✔️ | ✔️ | |

# WIP

We have some data available or change notifications configured, but there needs to be more work to recreate the events.

- [ ] [sumukha.com](https://sumukha.com) - Exhibitions and Art Fairs
- [ ] Sofar Bangalore
- [ ] [ICTS](https://www.icts.res.in/current-and-upcoming-events)
- [ ] lu.ma (Uses G-CSE, since no public calendars)
- [ ] Urbanaut
Expand Down Expand Up @@ -57,4 +57,5 @@ We have some data available or change notifications configured, but there needs
- [ ] https://en.wikipedia.org/wiki/Kempegowda_Museum
- [ ] https://en.wikipedia.org/wiki/Sandesh_Museum_of_Communication

[vism]: https://www.vismuseum.gov.in/special_events/upcoming-events-2/
[vism]: https://www.vismuseum.gov.in/special_events/upcoming-events-2/
[sofar]: https://www.sofarsounds.com/cities/bangalore
1 change: 1 addition & 0 deletions out/sofar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 2 additions & 1 deletion src/event-fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import json

EVENT_JSON_FILES = [
'out/bic.json'
'out/bic.json',
'out/sofar.json'
]

KNOWN_EVENT_TYPES = [
Expand Down
172 changes: 172 additions & 0 deletions src/sofar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import http.client
import datetime
import json

tz = datetime.timezone(datetime.timedelta(hours=5, minutes=30))


def to_schema_org_music_event(event_info):
base_url = "https://www.sofarsounds.com/events/"
guestsArriveAt = datetime.datetime.fromisoformat(
event_info.get("guestsArriveAt")
).astimezone(tz)
startsAt = datetime.datetime.fromisoformat(event_info.get("startsAt")).astimezone(
tz
)
# events are assumed to be 2 hours long
endsAt = startsAt + datetime.timedelta(hours=2)

venue = ""
categories = "/".join([x["name"] for x in event_info["venue"]["venueCategories"]])
if categories != "Other" :
venue = categories + " in "
venue += event_info["venue"]["neighborhood"]["title"]

# Mapping the provided dictionary to schema.org format
music_event_schema = {
"@context": "http://schema.org",
"@type": "MusicEvent",
"url": f"{base_url}{event_info['id']}",
"startDate": startsAt.isoformat(),
"doorTime": guestsArriveAt.isoformat(),
"endDate": endsAt.isoformat(),
"location": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressLocality": "Bangalore",
"addressRegion": "KA",
"addressCountry": "IN",
"streetAddress": venue,
},
"keywords": event_info["venue"]["venueType"],
},
}

return music_event_schema


def make_graphql_request(query, city, url):
headers = {"Content-Type": "application/json"}
body = json.dumps(
{
"operationName": "GetEventsForCityPage",
"variables": {
"city": city,
"excludeCancelled": True,
"excludeNonPresale": False,
"excludePresale": False,
"excludeSoldOut": False,
"globallyPromoted": True,
"includeNearbySecondaryCities": False,
"loadDynamicHeaderImages": False,
"page": 1,
"perPage": 12,
"published": True,
"skipPagination": False,
"upcoming": True,
},
"query": query,
}
)

conn = http.client.HTTPSConnection("www.sofarsounds.com")

conn.request("POST", "/api/v2/graphql?on=GetEventsForCityPage", body, headers)

data = json.loads(conn.getresponse().read())
conn.close()

return data


query = """
query GetEventsForCityPage(
$city: String
$includeNearbySecondaryCities: Boolean
$neighborhood: String
$date: String
$excludeSoldOut: Boolean
$excludePresale: Boolean
$excludeNonPresale: Boolean
$indoorOutdoor: String
$isByob: Boolean
$upcoming: Boolean
$published: Boolean
$globallyPromoted: Boolean
$type: String
$loadDynamicHeaderImages: Boolean
$page: Int
$perPage: Int
$skipPagination: Boolean
) {
events(
city: $city
includeNearbySecondaryCities: $includeNearbySecondaryCities
neighborhood: $neighborhood
date: $date
excludeSoldOut: $excludeSoldOut
excludePresale: $excludePresale
excludeNonPresale: $excludeNonPresale
indoorOutdoor: $indoorOutdoor
isByob: $isByob
upcoming: $upcoming
published: $published
globallyPromoted: $globallyPromoted
type: $type
loadDynamicHeaderImages: $loadDynamicHeaderImages
page: $page
perPage: $perPage
skipPagination: $skipPagination
) {
events {
id
guestsArriveAt
localStartsAt
startsAt
onPresale
isAppliable
isPublished
isPurchasable
cancelled
isSoldOut
city {
title
timezone
}
isVenueConfirmed
genres
neighborhood {
title
}
venue {
neighborhood {
title
}
venueType
venueCategories {
name
}
}
theme {
title
}
}
}
}
"""
url = "https://example.com/graphql"


def main():
response = make_graphql_request(query, "bangalore", url)
events = []
for d in response["data"]["events"]["events"]:
events.append(to_schema_org_music_event(d))
# write to out/sofar.json
with open("out/sofar.json", "w") as f:
json.dump(events, f, indent=2)


if __name__ == "__main__":
main()

0 comments on commit c5a4612

Please sign in to comment.