def _get_events(type_events, fetch_function, filter_function, page=1): user_id = unicode('all_public') if 'indico_user' in flask_session: if flask_session['indico_user']: user_id = flask_session['indico_user'] now = datetime.utcnow() events = _get_cached_events(user_id, type_events, now, page) if not events: offset = db_event.get_last_offset_cached(user_id, type_events) while len(events) < PAGE_SIZE: appended = 0 results = fetch_function(user_id, offset, PAGE_SIZE * 2) if not results: break for event in results: if filter_function(event, now): events.append(event) db_event.store_cached_event(user_id,type_events, now, event) appended += 1 if len(events) == PAGE_SIZE: break if len(events) == PAGE_SIZE: break offset += PAGE_SIZE * 2 db_event.remove_last_offset_cached(user_id, type_events) db_event.store_last_offset_cached(user_id, type_events, offset + appended) return events
def _filter_future_events(user_id, now, events): cached = False for event in events: if dt_from_indico(event['startDate']) - utc.localize(now) > timedelta( days=1) and not db_event.is_cached(user_id, event["id"]): cached = True db_event.store_cached_event(user_id, now, event) return cached
def _filter_future_events(user_id, now, events): cached = False for event in events: if dt_from_indico(event["startDate"]) - utc.localize(now) > timedelta(days=1) and not db_event.is_cached( user_id, event["id"] ): cached = True db_event.store_cached_event(user_id, now, event) return cached
def _filter_events(user_id, now, events): for event in events: if utc.localize(now) - dt_from_indico(event['startDate']) < timedelta( days=30): db_event.store_cached_event(user_id, now, event)
def _filter_events(user_id, now, events): for event in events: if utc.localize(now) - dt_from_indico(event["startDate"]) < timedelta(days=30): db_event.store_cached_event(user_id, now, event)