1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import pandas as pd
df = pd.read_csv('1.csv', encoding='gbk', header=0, parse_dates=[0,1], date_parser=lambda x: pd.to_datetime(x, format='%Y/%m/%d %H:%M'))
print(df)
from icalendar import Calendar, Event
cal = Calendar() cal.add('version', '2.0')
for row in df.itertuples(index=False): stime, etime, thing = row[0], row[1], row[2]
event = Event() event.add('summary', thing) event.add('dtstart', stime) event.add('dtend', etime)
cal.add_component(event)
txt = cal.to_ical() print(str(txt, encoding='utf8'))
with open('1.ics', 'wb') as f: f.write(txt)
|