Skip to content

Commit

Permalink
Update mapindia, enter the database
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Apr 1, 2024
1 parent ff13db3 commit 9ed153e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
commit_message: |
Automatic Updates 🤖
Database URL: ${{ steps.upload.artifact-url }}
Database URL: ${{ steps.upload.outputs.artifact-url }}
Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/workflow
commit_author: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>'
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ out/highape.txt:
python src/highape.py | sort > out/highape.txt

out/mapindia.json:
curl --silent --request GET \
--url 'https://map-india.org/wp-admin/admin-ajax.php?action=WP_FullCalendar&type=event&start=$(START_TS)&end=$(END_TS)' | jq -r '.' > out/mapindia.json
python src/mapindia.py

out/bengalurusustainabilityforum.json:
curl --silent --request GET \
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We either have URLs that can be easily scraped (https://schema.org/Event), or a
|:-------------------------------|:--------|:-------|:------------|:----------------------------------------------------------------------------------------------------------|
| AllEvents.in | ✔️ | ✔️ | ✔️ | |
| HighApe.com | ✔️ | ✔️ | ✔️ | |
| map-india.org | ✔️ | ✔️ | | |
| map-india.org | ✔️ | ✔️ | ✔️ | Only events, exhibits are not tracked yet
| BIC | ✔️ | ✔️ | ✔️ | Converted from ICS Calendar |
| Paytm Insider | ✔️ | ✔️ | ✔️ | |
| Bengaluru Sustainability Forum | ✔️ | ✔️ || |
Expand All @@ -21,8 +21,9 @@ We either have URLs that can be easily scraped (https://schema.org/Event), or a
| [NGMA][ngma] |||| OCR The [older website calender](http://www.ngmaindia.gov.in/ngma_bangaluru_calendar.asp) is not updated. |
| [Sofar][sofar] | ✔️ | ✔️ | ✔️ | |
| [Sumukha gallery][sumukha] | ✔️ | ✔️ | ✔️ |
| [Townscript][ts] | ✔️ | ✔️ | ✔️ | Lahe Lahe, Broke Bibliophiles, Foodwize
| [Blue Tokai][bt] | ✔️ | ✔️ | ✔️ | |
| [Townscript][ts] | ✔️ | ✔️ | ✔️ | Lahe Lahe, Broke Bibliophiles, Foodwize. Suggestions welcome for more events that use TownScript
| [Blue Tokai][bt] | ✔️ | ✔️ | ✔️ | Some location guesswork
| [Gully Tours][gt] | ✔️ | ✔️ | ✔️ | Sticker Price used, child pricing ignored
# WIP

We have some data available or change notifications configured, but there needs to be more work to recreate the events.
Expand Down Expand Up @@ -59,4 +60,5 @@ We have some data available or change notifications configured, but there needs
[sofar]: https://www.sofarsounds.com/cities/bangalore
[sumukha]: https://sumukha.com
[ts]: https://www.townscript.com/
[bt]: https://bluetokaicoffee.com/pages/events-new
[bt]: https://bluetokaicoffee.com/pages/events-new
[gt]: https://www.gully.tours/tours
1 change: 1 addition & 0 deletions src/event-fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'out/bluetokai.json',
'out/champaca.json',
'out/gullytours.json',
'out/mapindia.json',
]

KNOWN_EVENT_TYPES = [
Expand Down
71 changes: 71 additions & 0 deletions src/mapindia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import http.client
import json
from datetime import datetime, timedelta, timezone
from urllib.parse import urlencode

# TODO: We do not track Exhibits yet, only events
# Function to format datetime for allDay events
def format_datetime(dt, all_day):
tz = timezone(timedelta(hours=5, minutes=30))
if all_day:
return dt.strftime("%Y-%m-%d")
else:
return dt.replace(tzinfo=tz).isoformat()

start_ts = datetime.now().strftime("%Y-%m-%d")
end_ts = (datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d")

# Setup HTTP connection
conn = http.client.HTTPSConnection("map-india.org")

# Prepare parameters for the GET request
params = urlencode({
'action': 'WP_FullCalendar',
'type': 'event',
'start': start_ts,
'end': end_ts
})

# Perform the GET request
conn.request("GET", "/wp-admin/admin-ajax.php?" + params)
response = conn.getresponse()

# Check if the request was successful
if response.status == 200:
data = json.loads(response.read())
events = []

for item in data:
start_date = datetime.fromisoformat(item['start'])
end_date = datetime.fromisoformat(item['end'])
delta_days = (end_date - start_date).days + 1

for day in range(delta_days):
event_date = start_date + timedelta(days=day)
closing_time = end_date.replace(year=event_date.year, month=event_date.month, day=event_date.day)
event = {
"@context": "https://schema.org",
"@type": "Event",
"name": item['title'],
"startDate": format_datetime(event_date, item['allDay']),
"endDate": format_datetime(closing_time, item['allDay']),
"location": {
"@type": "Place",
"name": "Museum of Art & Photography (MAP)",
"address": "22, Kasturba Rd, Shanthala Nagar, Bengaluru, Karnataka 560001, India",
"url": "https://map-india.org/visit-us/",
"telephone": "+91 80 6933 4100"
},
"eventStatus": "https://schema.org/EventScheduled",
"url": item['url']
}
# if not item['allDay']:
# event["startDate"] = event["startDate"].replace("00:00:00", item['start'].split("T")[1])
# event["endDate"] = event["endDate"].replace("00:00:00", item['end'].split("T")[1])
events.append(event)

# Write the events to a JSON file
with open("out/mapindia.json", "w") as file:
json.dump(events, file, indent=2)
else:
print(f"Failed to fetch data. Status code: {response.status}")

0 comments on commit 9ed153e

Please sign in to comment.