Skip to content

Instantly share code, notes, and snippets.

@khafatech
Created March 13, 2009 06:43
Show Gist options
  • Save khafatech/78459 to your computer and use it in GitHub Desktop.
Save khafatech/78459 to your computer and use it in GitHub Desktop.
"""
Generate graph of prerequisites.
http://www.csupomona.edu/~cs/student/undergrad.shtml
"""
import urllib
import re
data = urllib.urlopen('http://www.csupomona.edu/~cs/student/undergrad.shtml').read()
d = {}
for c in re.finditer(r'name="(.*?)"(.*?)</block', data, re.M|re.S):
d[c.group(1)] = re.findall(r'#(.*?)"', c.group(2))
# generate graph
outf = open('classes.dot', 'w')
print >> outf, 'digraph classes {'
for k, v in d.items():
if v:
for preq in v: print >> outf, '%s -> %s;' %(preq, k)
else:
print >> outf, '%s;' % k
print >> outf, '}'
outf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment