8000 lichao's task1 by paytonpayton · Pull Request #2 · StarKnowData/Python · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions iCalendar/Lichao's task1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ics数据写入
from ics import Calendar, Event

c = Calendar()
c.version = "2.0"
c.prodid = "-//Payton Inc//Payton Calendar"
#创建事件
e = Event()
name = input("name: ")
begin = input("begin: ")
end = input("end: ")

e.name = name
e.begin = begin
e.end = end
c.events.add(e)
c.events
#写入事件
with open('payton.ics', 'a+') as f:
addData = f.writelines(c)


# ics数据读取
#解码并读取
f = open('payton.ics', 'rb')
c = Calendar(f.read().decode('iso-8859-1'))
s = c.events
#显示事件的结果
print(s)
e = c.events[0]
"Event '{}' started {}".format(e.name, e.begin.humanize())
127 changes: 127 additions & 0 deletions iCalendar/task1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name: payton's birthday\n",
"begin: 20190522 00:00\n",
"end: 20190523 00:00\n"
]
}
],
"source": [
"# ics数据写入\n",
"from ics import Calendar, Event\n",
"\n",
"c = Calendar()\n",
"c.version = \"2.0\"\n",
"c.prodid =\"-//Payton Inc//Payton Calendar\"\n",
"#创建事件\n",
"e = Event()\n",
"name = input(\"name: \")\n",
"begin = input(\"begin: \")\n",
"end = input(\"end: \")\n",
"e.name = name\n",
"e.begin = begin\n",
"e.end = end\n",
"c.events.add(e)\n",
"c.events\n",
"#写入事件\n",
"with open('payton.ics', 'a+') as f:\n",
" addData = f.writelines(c)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[<Event 'payton's birthday' begin:2019-05-22T00:00:00+00:00 end:2019-05-23T00:00:00+00:00>]\n"
]
},
{
"data": {
"text/plain": [
"\"Event 'payton's birthday' started in 4 months\""
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# ics数据读取\n",
"from ics import Calendar, Event\n",
"#解码并读取\n",
"f = open('payton.ics', 'rb')\n",
"c = Calendar(f.read().decode('iso-8859-1'))\n",
"s=c.events\n",
"#显示事件的结果\n",
"print(s)\n",
"e = c.events[0]\n",
"\"Event '{}' started {}\".format(e.name, e.begin.humanize())\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
0