Skip to content

Instantly share code, notes, and snippets.

@smac89
Last active August 29, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smac89/cdb334a9dea496cabedf to your computer and use it in GitHub Desktop.
Save smac89/cdb334a9dea496cabedf to your computer and use it in GitHub Desktop.
[SOLVED] The struggle to print your u of s schedule without unnecessary details filling up the page

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.

  1. Open your schedule in a browser:

  1. Right-click anywhere in the page and select Inspect Element:

  2. Inside the new window, type table.datadisplaytable into the search bar:

  3. Finally right click the highlighted row and select Copy Outer HTML or Copy HTML

  4. 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
  1. After the script has run it's course, it will produce a file called out.html. Open this file in your browser to see your schedule. Example:

  1. Print preview in this new page shows this:

vs

  1. To convert the file to a pdf (thus preserving the colours), use this site to do so: http://html2pdf.com/

Analytics

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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment