Skip to content

Commit

Permalink
New Source: Paint Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Jan 10, 2025
1 parent 935b191 commit 3825f20
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ out/lavonne.json:
out/bngbirds.json:
python src/bngbirds.py || $(call restore-file,$@)

out/paintbar.json:
python src/paintbar.py || $(call restore-file,$@)

fetch: out/allevents.txt \
out/highape.txt \
out/mapindia.json \
Expand Down Expand Up @@ -216,7 +219,8 @@ fetch: out/allevents.txt \
out/thewhitebox.json \
out/timeandspace.json \
out/lavonne.json \
out/bngbirds.json
out/bngbirds.json \
out/paintbar.json
@echo "Done"

clean:
Expand Down
58 changes: 58 additions & 0 deletions out/paintbar.json

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

12 changes: 12 additions & 0 deletions patch/paintbar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"@context": "https://schema.org",
"@type": "SocialEvent",
"inLanguage": "en",
"eventStatus": "EventScheduled",
"organizer": {
"@type": "Organization",
"name": "Paint Bar",
"url": "https://www.paintbar.in/"
},
"keywords": ["PAINTBAR"]
}
3 changes: 2 additions & 1 deletion src/event-fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"out/thewhitebox.json",
"out/timeandspace.json",
"out/lavonne.json",
"out/bngbirds.json"
"out/bngbirds.json",
"out/paintbar.json"
]

KNOWN_EVENT_TYPES = [
Expand Down
78 changes: 78 additions & 0 deletions src/paintbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import datefinder
import json
from datetime import datetime
from common.tz import IST
from common.shopify import Shopify, ShopifyProduct

DOMAIN = 'www.paintbar.in'
COLLECTION = 'paint-bar-bangalore'

# Convert variants to Schema.org/Offer
def make_offers(product: ShopifyProduct):
return [
{
"@type": "Offer",
"priceCurrency": "INR",
"price": variant.price,
}
for variant in product.variants
]

# Fetch timings from the variant.title. It returns start_date and end_date timestamps
def fetch_timings(date_str: str):
(_, date_part, time_part) = date_str.split(" | ")

event_date = list(datefinder.find_dates(date_part))[0]

for splitter in ["to", "-"]:
if splitter in time_part:
l = [x.strip() for x in time_part.split(splitter)]

if l == None:
raise ValueError("Could not find time in" + date_str)

known_twelveness = [
twelveness for twelveness in ["am", "pm"] for i in l if twelveness in i
]

timestamps = []

for time_str in l:
# check if time_str contains AM or PM
if not ("am" in time_str or "pm" in time_str):
time_str += known_twelveness[0]
timestamps.append(
list(datefinder.find_dates(time_str, base_date=event_date))[0].replace(
tzinfo=IST
)
)

if len(timestamps) != 2:
raise ValueError("Could not find time in" + date_str)

return timestamps


def make_event(product, sp: Shopify):
start_date, end_date = fetch_timings(product.title)
# URL may sometimes contain emojis, make sure they are encoded as EMOJI
print(product.url)

return {
"name": product.title,
"description": product.description,
"url": product.url,
"offers": make_offers(product),
"startDate": start_date.isoformat(),
"endDate": end_date.isoformat(),
}

if __name__ == "__main__":
from common.session import get_cached_session
session = get_cached_session()
paint_bar = Shopify(DOMAIN, session, COLLECTION)
events = [make_event(p, paint_bar) for p in paint_bar.products()]

with open("out/paintbar.json", "w") as f:
json.dump(events, f, indent=2, ensure_ascii=False)
print(f"[PAINTBAR] {len(events)} events")

0 comments on commit 3825f20

Please sign in to comment.