Exemplo n.º 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()
Exemplo n.º 2
0
def json_calendar_view(_id):
    calendar = Calendar.find(_id)
    return jsonify(calendar.to_dict())
Exemplo n.º 3
0
def ics_calendar_view(_id):
    calendar = Calendar.find(_id)
    return Response(calendar.to_ical(), mimetype='text/calendar')
Exemplo n.º 4
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)})
Exemplo n.º 5
0
def monitor():
    while True:
        for calendar_data in calendars.find({'data': {'$exists': True}}):
            calendar = Calendar.from_pickle(calendar_data['pickle'])
            Pooler.submit(parse_calendar, calendar.type, calendar.url, [None, None], calendar.data)
        time.sleep(int(os.getenv('MONITOR_DELAY') or 30))