from icalendar import Calendar, Event
import codecs

calendar_swe=Calendar()
calendar_swe.add('version', '2.0')
calendar_eng=calendar_swe.copy()

i_swe=1
i_eng=1
def create_event(summary, description, date, uid):
    event=Event()
    event['uid']=str(uid)
    event['dtstart']=''.join(date.split('-'))
    event['description']=description
    event['summary']=summary
    return event

for l in file('list.txt'):
    # encoding issues with swedish:
    l=codecs.decode(l, 'utf-8')
    lsp=l.split('  ')

    date=lsp[0].strip()
    desc_eng=lsp[1].split('/')[0].strip()
    desc_swe=lsp[1].split('/')[1].strip()
    reduction=lsp[-1].strip()
    
    event_swe=create_event(desc_swe, desc_swe+', '+reduction, date, i_swe)
    i_swe+=1
    calendar_swe.add_component(event_swe)

    event_eng=create_event(desc_eng, desc_eng+', '+reduction, date, i_eng)
    i_eng+=1
    calendar_eng.add_component(event_eng)

file('vacations_swe_2015.ics','w').writelines(calendar_swe.to_ical())
file('vacations_eng_2015.ics','w').writelines(calendar_eng.to_ical())