Created
October 22, 2015 21:35
-
-
Save drhodes/8a528fe5ee8085d6597e to your computer and use it in GitHub Desktop.
coursenotes2url.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
URL_TEMPLATE = "http://computationstructures.org/notes/%s/notes.html#TARGET_" | |
# takes a section number like 6.5.4 and converts it to a URL | |
def section_to_url(chapter, section): | |
lookup = { | |
'3': "information", | |
'4': "circuits", | |
'5': "digitalabstraction", | |
'6': "cmos", | |
'7': "combinational_logic", | |
'8': "sequential_logic", | |
'9': "fsms", | |
'10': "arbitration", | |
'11': "performance", | |
'12': "tradeoffs", | |
} | |
if chapter not in lookup: | |
raise Exception("Couldn't find this chapter: " + chapter) | |
chapterName = lookup[chapter] | |
return (URL_TEMPLATE % chapterName) + section | |
def chapter_from_section(section): | |
section = section.strip() | |
parts = section.split(".") | |
return parts[0] | |
def main(): | |
parser = argparse.ArgumentParser( | |
description= | |
"Get the URL that corresponds to a 6.004[x] Computation Structures \ | |
section number, such as '6.4.3'") | |
parser.add_argument('section', type=str) | |
args = parser.parse_args() | |
chapter = chapter_from_section(args.section) | |
url = section_to_url(chapter, args.section) | |
print url | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ chmod +x ./coursenotes2url.py
usage is like:
$ ./coursenotes2url.py 11.5.1
output is:
http://computationstructures.org/notes/performance/notes.html#TARGET_11.5.1