Commit 7a4f5f97 authored by Maxime Bombar's avatar Maxime Bombar

Move functions outside of __main__

parent 9913eb92
......@@ -15,6 +15,7 @@ import datetime
import icalendar
import re
import argparse
......@@ -27,6 +28,30 @@ today = datetime.datetime.strptime(
def get_string(tag):
return tag.string
def get_schedule(a):
"""
returns a list of the schedule for the 5 days of the week
from schedule website
"""
sched = [[]]*5 # 5 days
for i in range(5):
sched[i] = a[i*36:(i+1)*36]
return(sched)
def pretty_schedule(schedule):
days = []
for day in schedule:
cls = []
for i in range(len(day)):
try:
if regex.match(day[i].string):
cls.append(day[i:i+6])
except: # schedule bad format
pass
days.append(cls)
return format(days)
def format(days):
"""
......@@ -84,6 +109,11 @@ if __name__ == '__main__':
default = today
)
parser.add_argument(
"-p", "--pretty",
help="Pretty print",
action="store_true",
)
args = parser.parse_args()
......@@ -102,32 +132,11 @@ if __name__ == '__main__':
a = soup.find_all('big')[57:] # Fetch "Big" tags, begins from first class on Monday
def get_schedule(a):
"""
returns a list of the schedule for the 5 days of the week
"""
sched = [[]]*5 # 5 days
for i in range(5):
sched[i] = a[i*36:(i+1)*36]
return(sched)
import re
regex = re.compile('[0-9]*h[0-9]*-[0-9]*h[0-9]*') # regex time
days = []
schedule = get_schedule(a)
for day in schedule:
cls = []
for i in range(len(day)):
try:
if regex.match(day[i].string):
cls.append(day[i:i+6])
except: # schedule bad format
pass
days.append(cls)
days = pretty_schedule(schedule)
days = format(days)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment