-1

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 files). I found multidl python program. It works perfectly. All files url that I have to download are store in a txt file.

files format is like YYYYMMDD_Merdy.ics YYYYMMDD_test.ics

here an exemple of ics files

BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Chambre ChampĂȘtre
X-WR-TIMEZONE:Europe/Paris
BEGIN:VEVENT
DTSTART:20180407T140000Z
DTEND:20180408T080000Z
DTSTAMP:20181002T185454Z
UID:3a4j71mpemgjoo66anfd0tcvrh@google.com
CREATED:20180401T165816Z
DESCRIPTION:
LAST-MODIFIED:20180401T165816Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:direct Chantal
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART:20181001T150000Z
DTEND:20181002T080000Z
DTSTAMP:20181002T185454Z
UID:ccs6aor5cor3cbb270r3ab9kcpi6abb26di34b9kc9im8chj75hm4d35cc@google.com
CREATED:20181001T154801Z
DESCRIPTION:
LAST-MODIFIED:20181001T154801Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Ferme
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

The output I want is a csv file with the followinf format:

X-WR-CALNAME;DTSTART;DTEND;CREATED;LOCATION;SUMMARY
Chambre ChampĂȘtre;20180407T140000Z;20180408T080000Z;20180401T165816Z;direct Chantal;
Chambre ChampĂȘtre;20181001T150000Z;20181002T080000Z;20181001T154801Z;Ferme

The output csv file should contain all conversion from ICS files

fell free to ask me anything

Thanks all for helping me.

KiKine
  • 9
  • 3

1 Answers1

0

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()
Shravan Yadav
  • 1,297
  • 1
  • 14
  • 26