#! python import json import link_utils from utils import relative_to # The point of this script is to take raw_data.json and links.json # and combine it into data.json. # read in raw_data.json with open(relative_to(__file__, './raw_data.json'), 'r') as f: raw_data = f.read() data = json.loads(raw_data) # go through all courses, and look for a corresponding link. # old implementation set up a dictionary to speed this up, # but crosslisted courses caused trouble - hence now we look through # all links looking for a match for course in data: link_info = link_utils.find_link(course['name']) if 'link_fallback' in course: if not link_info: print 'Searching', course['name'], 'for fallback link' link_info = link_utils.find_link(course['link_fallback']) del course['link_fallback'] if link_info: course['link'] = link_info['tinylink']
#! python import json from utils import relative_to # read in links.json with open(relative_to(__file__, './links.json'), 'r') as f: links_json = f.read() links = json.loads(links_json) def find_link(course_name): for link_info in links: if link_info['pagetitle'].startswith(course_name): print "Matched", course_name, "to", repr(link_info['pagetitle']) return link_info print "Failed to find page matching", course_name return None def make_internal_link(course): '''takes a course, and returns the pagetitle of the course OR if there is no corresponding wiki page, creates a title for the course based on the encoded convention. WARNING: Changing this code could change red links generated in the future; if these are different that old red links that should point to the same page, it will cause red links to not link up automatically as they should. ''' if 'pagetitle' in course:
#! python import json from utils import relative_to # read in links.json with open(relative_to(__file__, './links.json'), 'r') as f: links_json = f.read() links = json.loads(links_json) def find_link(course_name): for link_info in links: if link_info['pagetitle'].startswith(course_name): print "Matched", course_name, "to", repr(link_info['pagetitle']) return link_info print "Failed to find page matching", course_name return None def make_internal_link(course): '''takes a course, and returns the pagetitle of the course OR if there is no corresponding wiki page, creates a title for the course based on the encoded convention. WARNING: Changing this code could change red links generated in the future; if these are different that old red links that should point to the same page, it will cause red links to not link up automatically as they should. '''