""" Program that grabs the specific lecture URLs from the CS51A course home page """ # David Kauchak from urllib.request import urlopen COURSE_PAGE = "http://www.cs.pomona.edu/~dkauchak/classes/cs51a/" def get_note_urls(page): """ Get the lecture URLs available from the course web page and return them in a list """ web_page = urlopen(page) urls = [] # all of the urls for lectures, start with "lectures/" search_line = "lectures/" for line in web_page: line = line.decode('ISO-8859-1').strip() if search_line in line: begin_index = line.find(search_line) end_index = line.find('"', begin_index) urls.append(page + line[begin_index:end_index]) return urls def write_list_to_file(some_list, output_file): """Write out all of the contents of the list to the file""" out = open(output_file, "w") out.write("Lecture notes for CS51A\n\n") for item in some_list: out.write(item + "\n") out.close() def write_lecture(outfile): # get the lecture urls lecture_urls = get_note_urls(COURSE_PAGE) # print them out to the file write_list_to_file(lecture_urls, outfile)