Skip to content

Commit

Permalink
bluetokai fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
captn3m0 committed Jan 10, 2025
1 parent 673d3fa commit a8a179b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
27 changes: 26 additions & 1 deletion out/bluetokai.json

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

21 changes: 19 additions & 2 deletions src/bluetokai.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
12.99609493,
77.6954406
),
(
"https://bluetokaicoffee.com/pages/blue-tokai-coffee-roasters-ub-city-bangalore",
"Blue Tokai Coffee Roasters UB City",
r"\bub city\b",
12.9717222,
77.59425
),
# This is not a cafe but their Roastery itself
(
"https://maps.app.goo.gl/fssZvwfXuxhaC7G77",
Expand Down Expand Up @@ -99,6 +106,13 @@
12.90694327,
77.59912373
),
(
"https://bluetokaicoffee.com/pages/blue-tokai-coffee-roasters-aecs-layout"
"Blue Tokai Coffee Roasters AECS Layout",
r"\baecs\b",
12.9633889,
77.7095833
)
]


Expand Down Expand Up @@ -141,17 +155,19 @@ def extract_timing(body_html):
)
if timing_match:
start_hour, start_period, end_hour, end_period = timing_match.groups()
# Convert to 24-hour format
start_hour = int(start_hour) % 12 + (12 if start_period.upper() == "PM" else 0)
end_hour = int(end_hour) % 12 + (12 if end_period.upper() == "PM" else 0)
# Sometimes we get a listing like Time: 11 PM - 4 PM
if start_hour > end_hour:
start_hour -= 12
return start_hour, end_hour
return None


def guess_location(body_html):
body_text = BeautifulSoup(body_html, "html.parser").get_text()
for line in body_text.split("\n"):
if "Bengaluru" in line:
if "Bengaluru" in line or "Koramangala" in line:
for location in LOCATIONS:
if re.search(location[2], line, re.IGNORECASE):
return (location[0], location[1], location[3], location[4])
Expand All @@ -163,6 +179,7 @@ def generate_event_object(product_json, variant, date, start_hour, end_hour):
)
end_datetime = datetime(date.year, date.month, date.day, end_hour, 0, tzinfo=IST)
(location_url, address, lat, lng) = guess_location(product_json["product"]["body_html"])

event = {
"url": f"https://bluetokaicoffee.com/products/{product_json['product']['handle']}",
"name": product_json["product"]["title"],
Expand Down

0 comments on commit a8a179b

Please sign in to comment.