add parsing of card schedule fields (#83742)
gitea/combo-plugin-gnm/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-11-21 10:06:27 +01:00
parent 608a3b2404
commit 9d1e5d96a2
1 changed files with 29 additions and 3 deletions

View File

@ -247,7 +247,31 @@ def parse_opening_hours_data(mairie_data):
yield (days_list, time_table)
def parse_mairie_formats(data, base_datetime, oh_add, ohs_add, ohs_del):
def parse_card_schedule_format(data, base_datetime, oh_add, ohs_add, ohs_del, card_field=None):
for schedule in data['fields'][card_field or 'horaire_ouverture_raw']:
opening_time = schedule['plage_horaire_debut']
if not opening_time:
continue
closing_time = schedule['plage_horaire_fin']
time_table = {
'start_hour': opening_time.split(':')[0],
'start_minute': opening_time.split(':')[1],
'end_hour': closing_time.split(':')[0],
'end_minute': closing_time.split(':')[1],
}
for weekday in schedule['jour_ouverture_raw']:
weekday_index = FR_WEEKDAYS.index(weekday.lower())
ohs_add(weekday_index, time_table)
return True
def parse_mairie_formats(data, base_datetime, oh_add, ohs_add, ohs_del, card_field=None):
if 'fields' in data and 'horaire_ouverture_raw' in data['fields']:
return parse_card_schedule_format(
data, base_datetime, oh_add, ohs_add, ohs_del, card_field=card_field
)
if 'properties' in data:
data = data['properties']
@ -306,7 +330,7 @@ def parse_valid_through(spec):
@register.simple_tag
def get_mairie_opening_hours(mairie_data):
def get_mairie_opening_hours(mairie_data, card_field=None):
"""Process Mairie Geojson to extract data of each day's opening hours"""
if not mairie_data:
@ -346,7 +370,9 @@ def get_mairie_opening_hours(mairie_data):
day += datetime.timedelta(days=1)
nb_days += 1
known_format = parse_mairie_formats(mairie_data, base_datetime, oh_add, ohs_add, ohs_del)
known_format = parse_mairie_formats(
mairie_data, base_datetime, oh_add, ohs_add, ohs_del, card_field=card_field
)
for weekday in exclusions:
opening_hours_dict[weekday] = {'am': None, 'pm': None}