<commit_before>from datetime import datetime, date
from icalendar import Calendar
import pytz
from helpers import attendee_to_login as to_log, format_room, set_utc, format_dt
import logging


def ical_to_dict(stream):
    """
    get all event of the CURRENT day and format them to a dict ready to be encoded in json

    :param stream: icalendar file object from get request
    :return: a dict containing formated data
    :rtype: dict
    """
    ret = []
    try:
        if hasattr(stream, 'content'):
            content = stream.content
        else:
            content = stream.read()
    except AttributeError:
        logging.error('Bad ics file provided')
        return False
    day_end = datetime.combine(date.today(), datetime.max.time()).replace(tzinfo=pytz.UTC)
    now = set_utc(datetime.now(tz=pytz.UTC))
    try:
        cal = Calendar.from_ical(content)
    except ValueError:
        logging.error('Bad ics file provided')
        return False
    for ev in cal.walk():
        if ev.name == 'VEVENT':
            ev_start = set_utc(ev.get('DTSTART').dt)
            ev_end = set_utc(ev.get('DTEND').dt)
            if ev_end > now >= ev_start:
                print ev_start
                event = {'place': format_room(ev.get('LOCATION').to_ical()),
                         'name': ev.get('SUMMARY').to_ical(),
                         'personnes': to_log(ev.get('ATTENDEE')),
                         'start': format_dt(ev_start),
                         'end': format_dt(ev_end)}
                ret.append(event)
    next_ev = [{'name': ev.get('SUMMARY').to_ical(),
                'place': format_room(ev.get('LOCATION').to_ical().replace('\\', '')),
                'end': format_dt(set_utc(ev.get('DTEND').dt)),
                'start': format_dt(set_utc(ev.get('DTSTART').dt))}
               for ev in cal.walk()
               if ev.name == "VEVENT" and (now < ev.get('DTSTART').dt <= day_end)]
    next_ev = sorted(next_ev, key=lambda k: k['start'])
    val = {'current_events': ret, 'next_events': next_ev}
    return val<commit_msg>now take events of the next days for next_events<commit_after>from datetime import datetime, date, timedelta
from icalendar import Calendar
import pytz
from helpers import attendee_to_login as to_log, format_room, set_utc, format_dt
import logging


def ical_to_dict(stream):
    """
    get all event of the CURRENT day and format them to a dict ready to be encoded in json

    :param stream: icalendar file object from get request
    :return: a dict containing formated data
    :rtype: dict
    """
    ret = []
    try:
        if hasattr(stream, 'content'):
            content = stream.content
        else:
            content = stream.read()
    except AttributeError:
        logging.error('Bad ics file provided')
        return False
    day_end = datetime.combine(date.today(), datetime.max.time()).replace(tzinfo=pytz.UTC)
    now = set_utc(datetime.now(tz=pytz.UTC))
    try:
        cal = Calendar.from_ical(content)
    except ValueError:
        logging.error('Bad ics file provided')
        return False
    for ev in cal.walk():
        if ev.name == 'VEVENT':
            ev_start = set_utc(ev.get('DTSTART').dt)
            ev_end = set_utc(ev.get('DTEND').dt)
            if ev_end > now >= ev_start:
                print ev_start
                event = {'place': format_room(ev.get('LOCATION').to_ical()),
                         'name': ev.get('SUMMARY').to_ical(),
                         'personnes': to_log(ev.get('ATTENDEE')),
                         'start': format_dt(ev_start),
                         'end': format_dt(ev_end)}
                ret.append(event)
    next_ev = [{'name': ev.get('SUMMARY').to_ical(),
                'place': format_room(ev.get('LOCATION').to_ical().replace('\\', '')),
                'end': format_dt(set_utc(ev.get('DTEND').dt)),
                'start': format_dt(set_utc(ev.get('DTSTART').dt))}
               for ev in cal.walk()
               if ev.name == "VEVENT" and (now < ev.get('DTSTART').dt <= day_end + timedelta(days=1))]
    next_ev = sorted(next_ev, key=lambda k: k['start'])
    val = {'current_events': ret, 'next_events': next_ev}
    return val
{'fraction_non_alphanumeric': 0.131353919239905, 'fraction_numerical': 0.00023752969121140142, 'mean_word_length': 2.2592879256965945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '897104', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1279, 'n_words': 317}