Beispiel #1
0
def parse_calendar(type_, file, user_geo, existing_data=None):
    print('Processing {}'.format(file))
    importer = Importer.get_importer(type_)
    data = importer().open(file).read()
    if not data:
        Calendar.from_url(file, type_).destroy()
        return
    if data == existing_data:
        return
    events = Parser().parse(data)
    if all(user_geo):
        for event in events:
            if not event.latitude:
                cache_geolocation_info_for_event(event, *user_geo)
    calendar = Calendar(file, type_, data, events)
    return calendar.save()
Beispiel #2
0
def api_create_view():
    calendar = Calendar.from_url(request.form['url'], request.form['type'])
    _id = calendar.save()
    user_geo = (request.form.get('lat'), request.form.get('lng'))
    Pooler.submit(parse_calendar, request.form['type'], request.form['url'], user_geo)
    return jsonify({'status': 'success', 'id': str(_id)})