带有ICS文件和CSV的Python

编程入门 行业动态 更新时间:2024-10-26 00:20:20
本文介绍了带有ICS文件和CSV的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一个朋友问我一个个人项目的帮助,但是我不得不承认我的Python技能是非常基础的.

one friend ask me some help on a personnal project, but I have to admit my skills in Python are very basics.

这里是个主意:

我必须下载Multplie ics文件(Google日历文件).我找到了multidl python程序.它完美地工作.我必须下载的所有文件URL都存储在一个txt文件中.

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.

文件格式类似于YYYYMMDD_Merdy.ics YYYYMMDD_test.ics

files format is like YYYYMMDD_Merdy.ics YYYYMMDD_test.ics

此处是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 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 CREATED:20181001T154801Z DESCRIPTION: LAST-MODIFIED:20181001T154801Z LOCATION: SEQUENCE:0 STATUS:CONFIRMED SUMMARY:Ferme TRANSP:OPAQUE END:VEVENT END:VCALENDAR

我想要的输出是具有followinf格式的csv文件:

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

输出的csv文件应包含ICS文件中的所有转换

The output csv file should contain all conversion from ICS files

随意问我

谢谢大家的帮助.

推荐答案

下面是一个解决方案.让我知道是否有帮助.在这里,我从目录C:/Users/Dell/Documents中读取所有.ics文件.您的情况有所不同.

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()

更多推荐

带有ICS文件和CSV的Python

本文发布于:2023-05-29 23:12:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/355147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   ICS   Python   CSV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!