# Path: indicomobile/util/date_time.py
# def dt_from_indico(dt_dict):
#     dt = datetime.combine(datetime.strptime(dt_dict['date'], "%Y-%m-%d"),
#                           datetime.strptime(dt_dict['time'].split('.')[0], "%H:%M:%S").time())
#     return timezone(dt_dict['tz']).localize(dt)
# 
# Path: indicomobile/core/cache.py
# def setup_caching(app):
# def make_cache_key(*args, **kwargs):


from pytz import utc
from datetime import timedelta, datetime
from flask import session as flask_session, abort
from indicomobile.util.date_time import dt_from_indico
from indicomobile.core.cache import cache, make_cache_key
import urllib
import indicomobile.db.event as db_event
import indicomobile.db.session as db_session
import indicomobile.db.contribution as db_contribution
import indicomobile.core.indico_api as api
import indicomobile.core.favorites as favorites
        if not db_event.get_event(event['id']):
            # store event
            event_tt = api.fetch_timetable(event['id'])
            db_event.store_event(event, event_tt)

    now = datetime.utcnow()
    tomorrow = now + timedelta(hours=6)
    results = list(db_contribution.get_contributions(now, tomorrow, [{'hasAnyProtection': False},
                                                                     {'_fossil': 'contribSchEntryDisplay'}])) \
            + list(db_event.get_ongoing_lectures(now, tomorrow))
    return sorted(results, key=lambda x: x['startDate'])

def get_event_day_contributions(event_id, day_date):
    start_date = datetime.strptime(day_date, '%Y-%m-%d')
    end_date = start_date + timedelta(days=1)
    return list(db_contribution.get_contributions(start_date, end_date, [{'conferenceId': event_id}]))


def get_session_day_contributions(event_id, session_id, day):
    start_date = datetime.strptime(day, '%Y-%m-%d')
    end_date = start_date + timedelta(days=1)
    contributions = db_session.get_session_day_contributions(event_id, session_id, start_date, end_date)
    return sorted(contributions.values(), key=lambda x: x['startDate'])


# SESSIONS

def get_event_sessions(event_id):
    event = db_event.get_event(event_id)


# Path: indicomobile/util/date_time.py
# def dt_from_indico(dt_dict):
#     dt = datetime.combine(datetime.strptime(dt_dict['date'], "%Y-%m-%d"),
#                           datetime.strptime(dt_dict['time'].split('.')[0], "%H:%M:%S").time())
#     return timezone(dt_dict['tz']).localize(dt)
# 
# Path: indicomobile/core/cache.py
# def setup_caching(app):
# def make_cache_key(*args, **kwargs):


# Path: indicomobile/core/event.py
from pytz import utc
from datetime import timedelta, datetime
from flask import session as flask_session, abort
from indicomobile.util.date_time import dt_from_indico
from indicomobile.core.cache import cache, make_cache_key
import urllib
import indicomobile.db.event as db_event
import indicomobile.db.session as db_session
import indicomobile.db.contribution as db_contribution
import indicomobile.core.indico_api as api
import indicomobile.core.favorites as favorites

        if not db_event.get_event(event['id']):
            # store event
            event_tt = api.fetch_timetable(event['id'])
            db_event.store_event(event, event_tt)

    now = datetime.utcnow()
    tomorrow = now + timedelta(hours=6)
    results = list(db_contribution.get_contributions(now, tomorrow, [{'hasAnyProtection': False},
                                                                     {'_fossil': 'contribSchEntryDisplay'}])) \
            + list(db_event.get_ongoing_lectures(now, tomorrow))
    return sorted(results, key=lambda x: x['startDate'])

def get_event_day_contributions(event_id, day_date):
    start_date = datetime.strptime(day_date, '%Y-%m-%d')
    end_date = start_date + timedelta(days=1)
    return list(db_contribution.get_contributions(start_date, end_date, [{'conferenceId': event_id}]))


def get_session_day_contributions(event_id, session_id, day):
    start_date = datetime.strptime(day, '%Y-%m-%d')
    end_date = start_date + timedelta(days=1)
    contributions = db_session.get_session_day_contributions(event_id, session_id, start_date, end_date)
    return sorted(contributions.values(), key=lambda x: x['startDate'])


# SESSIONS

def get_event_sessions(event_id):
    event = db_event.get_event(event_id)


    if not event: