<commit_before><commit_msg>Create a script for printing the chatroom topic with the next event.<commit_after>import urllib
import yaml
from datetime import datetime
from icalendar import Calendar

# Load configuration data
with open('config.yaml', 'r') as f:
    config = yaml.load(f)

calendar = config['calendar']
topic_format = config['irc']['topic']
date_format = config['date_format']

def next_event(ical_url):
    raw_ics = urllib.urlopen(ical_url).read()
    gcal = Calendar.from_ical(raw_ics)

    events = []

    for component in gcal.walk():
        if component.name != 'VEVENT':
            continue
        events.append(component);

    def compare(a, b):
        return cmp(a.get('dtstart').dt, b.get('dtstart').dt);

    sorted_events = sorted(events, compare)

    return sorted_events[0]

def chatroom_topic(event):
    start = event.get('dtstart').dt
    topic = topic_format.format(
        datetime=start.strftime(date_format),
        location=event.get('location')
    )
    return topic

print chatroom_topic(next_event(calendar))
{'fraction_non_alphanumeric': 0.11931818181818182, 'fraction_numerical': 0.000946969696969697, 'mean_word_length': 3.8045454545454547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1471889', 'n_tokens_mistral': 331, 'n_tokens_neox': 319, 'n_words': 78}