Skip to content
Snippets Groups Projects
Commit 39ab6cbe authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

upgrade to python3

parent 1e155f9f
No related branches found
No related tags found
No related merge requests found
from icalendar import Calendar, Event
import codecs
import os
def create_event(summary, description, date, uid):
......@@ -10,10 +9,16 @@ def create_event(summary, description, date, uid):
event['summary']=summary
return event
calendar_swe_all=Calendar()
calendar_swe_all.add('version', '2.0')
calendar_eng_all=calendar_swe_all.copy()
i_swe_all=1
i_eng_all=1
for f in os.listdir('.'):
if f.split('_')[0]=='list':
year=f.split('.')[0].split('_')[1]
print f,year
print(f,year)
calendar_swe=Calendar()
calendar_swe.add('version', '2.0')
......@@ -22,23 +27,32 @@ for f in os.listdir('.'):
i_swe=1
i_eng=1
for l in file(f):
for l in open(f, 'r', encoding="utf8"):
# 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_{}.ics'.format(year),'w').writelines(calendar_swe.to_ical())
file('vacations_eng_{}.ics'.format(year),'w').writelines(calendar_eng.to_ical())
event_swe_all=create_event(desc_swe, desc_swe+', '+reduction, date, i_swe_all)
i_swe_all+=1
calendar_swe_all.add_component(event_swe_all)
event_eng_all=create_event(desc_eng, desc_eng+', '+reduction, date, i_eng_all)
i_eng_all+=1
calendar_eng_all.add_component(event_eng_all)
open('vacations_swe_{}.ics'.format(year),'wb').write(calendar_swe.to_ical())
open('vacations_eng_{}.ics'.format(year),'wb').write(calendar_eng.to_ical())
open('vacations_swe.ics','wb').write(calendar_swe_all.to_ical())
open('vacations_eng.ics','wb').write(calendar_eng_all.to_ical())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment