Skip to content Skip to sidebar Skip to footer

Python With Ics Files And Csv

one friend ask me some help on a personnal project, but I have to admit my skills in Python are very basics. Here the idea: I have to download multplie ics files (google calendar f

Solution 1:

One solution for this is below. Let me know if it helps. Here I am reading all .ics file from directory C:/Users/Dell/Documents. In your case it is different.

from os import listdir

filenames = listdir(r'C:/Users/Dell/Documents')

for filename in filenames:
    if filename.endswith('.ics'):
        file=open(filename,"r")
        outputhead=['X-WR-CALNAME','DTSTART','DTEND','CREATED','LOCATION','SUMMARY']
        datalist=[]
        outfile=open(filename+'ouput.csv',"w")
        outfile.write(';'.join(outputhead))
        outfile.write('\n')
        outfile.close()
        outfile=open(filename+'ouput.csv',"a+")
        for i in file:
            if i.split(':')[0] in outputhead:
                datalist.append(i.split(':')[1].replace('\n',''))
            if i.split(':')[0]=='SUMMARY':
                outfile.write(';'.join(datalist))
                outfile.write('\n')
                datalist=[]
        outfile.close()

Post a Comment for "Python With Ics Files And Csv"