代码拉取完成,页面将自动刷新
import pandas as pd
import uuid,sys
#讲师名称(Excel中字段名)
name = "刘煜(西安)"
#导出课表的月份
month = "2021-6"
#输出文件名
output = name + month + '课程安排.ics'
if len(sys.argv) < 2:
print("请指定Excel文件")
sys.exit()
cal = pd.read_excel(sys.argv[1], sheet_name=0, skiprows=1)
#选择列
cal = cal[["讲师", name]].set_index('讲师')
courses = pd.Series(cal[name], index=cal.index)
#删除无安排的日期
courses = courses[courses.notnull()]
with open(output, 'w', encoding = 'utf-8') as f:
f.write("BEGIN:VCALENDAR\n")
f.write("PRODID:-//HQYJ//Curriculum//EN\n")
f.write("VERSION:2.0\n")
f.write("METHOD:PUBLISH\n")
#遍历指定月份的课程安排
for date, course in courses[month].items():
f.write("BEGIN:VEVENT\n")
f.write("DTSTART;VALUE=DATE:%s\n" % str(date.strftime("%Y%m%d")))
f.write("SUMMARY:%s\n" % course)
f.write("UID:%s\n" % str(uuid.uuid1()))
f.write("TRANSP:TRANSPARENT\n")
f.write("END:VEVENT\n")
f.write("END:VCALENDAR\n")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。