Python with ICS files and CSV [duplicate]

2024/11/16 11:48:07

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:[email protected]
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.

Answer

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 listdirfilenames = 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()
https://en.xdnf.cn/q/119535.html

Related Q&A

loading my data in numpy genfromtxt get errors

I have my data file contain 7500 lines with :Y1C 1.53 -0.06 0.58 0.52 0.42 0.16 0.79 -0.6 -0.3 -0.78 -0.14 0.38 0.34 0.23 0.26 -1.8 -0.1 -0.17 0.3…

Install dlib with cuda support ubuntu 18.04

I have CUDA 9.0 and CUDNN 7.1 installed on Ubuntu 18.04(Linux mint 19). Tensorflow-gpu works fine on GPU(GTX 1080ti).Now i am trying to build dlib with CUDA support:sudo python3 setup.py install --yes …

View 3 dimensional Numpy array in Matplotlib and taking arguments from Keyboard or mouse

I have 3 dimensional data say (5,100,100). Now I would like to see them slice by slice upon hitting the down arrow button.

python default argument syntax error

I just wrote a small text class in python for a game written using pygame and for some reason my default arguments arent working. I tried looking at the python documentation to see if that might give m…

Variable not defined (Python)

FlightType=input("Which flight would you like to fly? Type 2 Seater, 4 Seater, or Historic.") # No validation included for the inputFlightLen=input("Would you like to book the 30 minu…

PyGame: draw.rect() has invalid parameters

Im trying to learn mouse events with PyGame, and Im trying to draw a box wherever the user clicks. Im setting a variable equal to pygame.mouse.get_pos(), and calling individual tuple members according …

Cant press enter in selenium2library

Im trying to make a test that will open Facebook, log in and search something. However Im having trouble getting Facebook to search. Selenium types whatever it needs in the search bar, but I cant find …

Converting string to datetime in Python using strptime

Im trying to convert the following String to datetime object in Python.datetime_object = datetime.strptime(Sat, 26 Nov 2016 15:17:00 +0000, %a, %b %d %Y %H:%c %z)I get the following error,File "&l…

Is there any differences between python2 and python3 about adding menu bar to Frame in tkinter?

Im trying to porting a project 2to3 on python, and stuck in tkinter.In python2, there is no problem with adding menu bar to Frame in tkinter,but python3 occured attribute error. (Frame object has no at…

Standard Input having weird characters with them in different programming lanuage

I am getting confused with the standard input of these programming languages : [Note:] I added details about so many programming languages as the problem with all of them is same in this matter and my …