-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape_dates.py
33 lines (27 loc) · 926 Bytes
/
scrape_dates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# returns true if a string can be represented as an int
def is_int(string):
try:
int(string)
return True
except ValueError:
return False
# searches through each line of the file for a date and appends it to
# an array which is later returned
def get_dates_arr(course):
file_name = "./course-lecture-pages/"+course+".txt"
print("Fetching dates from "+course+".txt...")
file = open(file_name, "r")
dates = []
for line in file:
first_char = line[0:1]
# If the line starts with an int, it is presumed to be a date
if is_int(first_char):
date_input = line.split()[0:2]
day_str = date_input[0]
month_str = date_input[1]
date_formatted = day_str+" "+month_str
try:
dates.index(date_formatted)
except:
dates.append(date_formatted)
return dates