Skip to content

Commit

Permalink
Merge pull request #6 from kyle-seongwoo-jun/master
Browse files Browse the repository at this point in the history
  • Loading branch information
sookcha authored Sep 4, 2022
2 parents a603ba2 + 6d8de43 commit 9f2005b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 5 additions & 6 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
__author__ = "Hoseong Son <[email protected]>"

import datetime
import os
import xml.etree.ElementTree as ElementTree
from dateutil import parser
from icalendar import Calendar, Event
Expand Down Expand Up @@ -55,11 +54,11 @@ def get_calendar(self, timetable, start_date, end_date):
event.add('location', time["place"])
cal.add_component(event)

f = open(os.path.join('', 'calendar.ics'), 'wb')
f.write(cal.to_ical())
f.close()

print("작업 완료!🙌")
return cal

def export_calender_as_ics(self, cal, path):
with open(path, 'wb') as f:
f.write(cal.to_ical())

def get_nearest_date(self, start_date, weekday):
start_date = parser.parse(start_date)
Expand Down
14 changes: 11 additions & 3 deletions every2cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@
__author__ = "Hoseong Son <[email protected]>"

import argparse
import os

from convert import Convert


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--id", type=str, help="Everytime timetable id", required=False)
parser.add_argument("--xml", type=str, help="Location of timetable xml file", required=False)
parser.add_argument("--begin", type=str, help="Semester beginning date", required=True)
parser.add_argument("--end", type=str, help="Semester ending date", required=True)
parser.add_argument("--output", type=str, help="Output file path", required=False)
args = parser.parse_args()

xml = ""
if (args.xml):
xml = args.xml
else:
path = input('경로 : ')
path = args.id if (args.id) else input('경로 : ')

e = everytime.Everytime(path)
xml = e.get_timetable()

c = Convert(xml)
c.get_calendar(c.get_subjects(), args.begin, args.end)
cal = c.get_calendar(c.get_subjects(), args.begin, args.end)
output_path = args.output if (args.output) else os.path.join('', 'calendar.ics')
c.export_calender_as_ics(cal, output_path)

print("작업 완료!🙌")


if __name__ == '__main__':
main()
main()

0 comments on commit 9f2005b

Please sign in to comment.