def generate_event_pages(events, all_events): for event in events: result = template.render(event=event, all_events=all_events) filepath = generate_event_details_path(event) with open('build/' + filepath, 'w') as f: f.write(result)
def parse_event(row, today): start_of_month = get_start_of_month(today) end_of_today = get_end_of_day(today) try: start_date = datetime.strptime(row['datestart'], '%Y%m%d') except ValueError: pprint('error parsing datestart') pprint(row) return None start_day = start_date.strftime('%d') start_month = start_date.strftime('%m') start_year = start_date.strftime('%Y') end_date = datetime.strptime(row['dateend'], '%Y%m%d') end_day = end_date.strftime('%d') upcoming_event = end_date >= today classes = event_type_class_map.get(row['type'], '') if row['coclink'] and row['coclink'] != 'nococ': coc_link = row['coclink'] else: coc_link = None if row['city'] == '--' or not row['city']: city = '' else: city = row['city'] if row['country'] == '--' or not row['country']: country = '' else: country_code = row['country'].strip() country = iso_label_dict.get(country_code, country_code) if row['EntranceFee'] != '0': fee = row['EntranceFee'] else: fee = None if row['ParticipantsLastTime']: participants = row['ParticipantsLastTime'] else: participants = '?' try: lat = float(row['lat']) lon = float(row['lon']) geo = 'geo:' + str(lat) + ',' + str(lon) except: lat = None lon = None geo = None cfp = extract_cfp(row, today) event = { 'label': row['label'], 'editions_topic': row.get('Edition’s Topic', None), 'main_organiser': row.get('Main Organiser', None), 'description': row['Self-description'], 'specialities': row.get('Specialties', None), 'start_date': start_date, 'start_day': start_day, 'start_month': start_month, 'start_month_string': months[start_month], 'start_year': start_year, 'end_date': end_date, 'end_day': end_day, 'homepage': row['homepage'], 'fee': fee, 'venue': row['venue'], 'city': city, 'country': country, 'osm_link': row['OSM-Link'], 'geo': geo, 'main_language': row.get('Main language', '?'), 'cfp_date': cfp['cfp_date'], 'cfp_passed': cfp['cfp_passed'], 'cfp_link': cfp['cfp_link'], 'cfp_raw_link': cfp['cfp_raw_link'], 'coc_link': coc_link, 'registration': row['Registration'], 'classes': classes, 'type': row.get('type', '?'), 'upcoming': upcoming_event, 'participants': participants, 'lat': lat, 'lon': lon } event['ical_path'] = generate_event_ical_path(event) readable_location = event['venue'] if event['venue'] and event['city']: readable_location += ', ' readable_location += event['city'] if (event['venue'] or event['city']) and event['country']: readable_location += ', ' readable_location += event['country'] event['readable_location'] = readable_location if row['type'] == 'Global Day' or row['type'] == 'Regional Day': event['has_details'] = False event['details_url'] = row['homepage'] event['abs_details_url'] = row['homepage'] else: event['has_details'] = True event['details_url'] = generate_event_details_path(event) event['abs_details_url'] = 'https://foss.events/' + str( event['details_url']) meta_keywords = extract_meta_keywords(row) keyword_sep = ', ' event['keywords_string'] = keyword_sep.join(meta_keywords) return event