def generate_event_ical_files(events, now):
    for event in events:
        cal = Calendar()
        cal.add('prodid', '-//foss.events//foss.events//')
        cal.add('version', '2.0')
        cal_event = generate_ical_event(event, now)
        cal.add_component(cal_event)

        filepath = generate_event_ical_path(event)
        with open('build/' + filepath, 'wb') as f:
            f.write(cal.to_ical())
Beispiel #2
0
def generate_event_ical_files(events):
    for event in events:

        cal = Calendar()
        cal.add('prodid', '-//foss.events//foss.events//')
        cal.add('version', '1.3.3.7')

        cal_event = Event()
        cal_event.add('summary', event['label'])
        cal_event.add('dtstart', vDate(event['start_date']))

        cal_end_date = event['end_date'] + timedelta(days=1)
        cal_event.add('dtend', vDate(cal_end_date))

        cal_event.add('location', event['readable_location'])
        cal_event.add('url', vUri(event['abs_details_url']))

        description = event['description'] or ''
        description += '\n\n'

        if event['has_details']:
            description += 'Read everything about ' + event[
                'label'] + ' in a nutshell on // foss.events: ' + event[
                    'abs_details_url'] + '\n\n'

        description += 'Official Homepage: ' + event['homepage'] + '\n\n'

        if event['osm_link']:
            description += 'Find your way: ' + event['osm_link'] + '\n'

        cal_event['description'] = remove_tags(description)

        cal.add_component(cal_event)

        if event['lat'] and event['lon']:
            cal_event['geo'] = vGeo([event['lat'], event['lon']])

        filepath = generate_event_ical_path(event)
        with open('build/' + filepath, 'wb') as f:
            f.write(cal.to_ical())
Beispiel #3
0
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