Skip to content

Fix opens_at keeping the raw separator on non-English locales - #20

Open
Benjapieres wants to merge 1 commit into
zohaibbashir:mainfrom
Benjapieres:fix/opens-at-separator
Open

Fix opens_at keeping the raw separator on non-English locales#20
Benjapieres wants to merge 1 commit into
zohaibbashir:mainfrom
Benjapieres:fix/opens-at-separator

Conversation

@Benjapieres

Copy link
Copy Markdown

Problem

extract_place() splits the opening-hours string on (U+22C5 DOT OPERATOR) to drop the leading open/closed status. Google serves · (U+00B7 MIDDLE DOT) in at least some locales. The two characters render almost identically but are not equal, so the split never matches, falls through to the else branch, and stores the whole raw string.

Scraping "cafeterias en Palermo Buenos Aires" on current main gives:

' · Cierra a las 8p.m.'
'Abierto · Cierra a las 8p.m.'
' · Cierra a las 9p.m.'

instead of the intended 'Cierra a las 8p.m.'. Note the field is also inconsistent row to row, depending on whether the status prefix happened to be present — so it can't be parsed downstream either.

Confirmed by codepoint rather than by eye:

[hex(ord(c)) for c in opens_at if ord(c) > 127]   # -> ['0xb7']
hex(ord('⋅'))                                      # -> 0x22c5   what main.py splits on

Fix

parse_opens_at() accepts either separator and strips the result. U+22C5 is tried first, so locales that already worked keep their exact current behavior. Both characters are spelled as \u escapes because they are indistinguishable in source.

The two duplicated extraction branches collapse into one — the only difference between them was which XPath produced the raw string, so or covers the fallback.

Verification

Live scrape after the fix:

'Abre a las 7p.m.'            <- Winston Club
'Abre a las 12p.m.'           <- Estilo Campo Restaurante
'Abre a las 8p.m.'            <- Brukbar Buenos Aires
'Abre a las 7p.m. del jue'    <- Behind Bar

Parser cases, including the old separator and no-separator inputs:

input output
' · Cierra a las 8p.m.' 'Cierra a las 8p.m.'
'Abierto · Cierra a las 8p.m.' 'Cierra a las 8p.m.'
'Open ⋅ Closes 8 PM' (U+22C5) 'Closes 8PM'
'Abierto 24 horas' (sin separador) 'Abierto 24 horas'
'Cerrado' 'Cerrado'

Independent of #19 — different function, no overlap.

🤖 Generated with Claude Code

extract_place() splits the opening-hours string on U+22C5 DOT OPERATOR
to drop the leading open/closed status, but Google serves U+00B7 MIDDLE
DOT in at least some locales. The two render almost identically, so the
split silently never matches, falls through to the else branch and
stores the whole raw string.

Scraping "cafeterias en Palermo Buenos Aires" currently yields:

    ' · Cierra a las 8p.m.'
    'Abierto · Cierra a las 8p.m.'

instead of the intended 'Cierra a las 8p.m.'. The field is inconsistent
between rows depending on whether the status prefix was present.

parse_opens_at() now accepts either separator and strips the result.
U+22C5 is tried first, so locales that already worked are unaffected.
The two duplicated extraction branches collapse into one, since the
only difference between them was which XPath produced the raw string.

Verified against a live scrape:

    'Abre a las 7p.m.'            <- Winston Club
    'Abre a las 12p.m.'           <- Estilo Campo Restaurante
    'Abre a las 8p.m.'            <- Brukbar Buenos Aires

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant