[SOLVED] The struggle to print your u of s schedule without unnecessary details filling up the page
import sys
import re
class Beautify:
def __init__(self, fname):
self.head = \
"""<head>
<link rel="stylesheet" href="%s">
</head>
""" % "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
with open(fname, 'r') as f:
self.htmlstring = f.read()
def filter_html(self):
table_style = "table table-striped table-bordered table-condensed"
reg = re.compile('<table(.*?)class=".*?"(.*?)>(.*</table>)', re.S|re.I)
table = reg.search(self.htmlstring).group(0)
table_cleaned = reg.sub(r'<table\1class="%s"\2>\3'%table_style, table)
table_cleaned = re.sub(r'\s*class="d.*?"', '', table_cleaned)
table_cleaned = re.sub(r'href=".*?"', '', table_cleaned)
self.htmlstring = self.head + """\n<body class=table-responsive>\n
<div style=\"display:inline-block;\">\n""" + table_cleaned + "\n</div>\n</body>"
def writeout(self, fname):
self.filter_html()
with open(fname + ".html", 'w+') as out:
out.write(self.htmlstring)
if __name__ == '__main__':
cleaner = Beautify(sys.argv[1])
cleaner.writeout(sys.argv[2])
This is a method to get a clear, printable version of your uofs time table. This method involves a little work from you, then the attached app below does the rest. For this method to work well, you need to use firefox browser, as the end result looks off on chrome.
Right-click anywhere in the page and select Inspect Element
:
Inside the new window, type table.datadisplaytable
into the search bar:
Finally right click the highlighted row and select Copy Outer HTML
or Copy HTML
Copy this into a file and save the file. Assuming you called the file sched.html
, here is how you will then use the script:
python unscramble.py sched.html out
out.html
. Open this file in your browser to see your schedule. Example:vs