Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active August 31, 2017 08:35
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 MartinThoma/056183bc0862a787a8d4e8fe57e51f3f to your computer and use it in GitHub Desktop.
Save MartinThoma/056183bc0862a787a8d4e8fe57e51f3f to your computer and use it in GitHub Desktop.
Generate a HTML file with a big table.
#!/usr/bin/env python
import random
random.seed(0)
rows = 100
cols = 15
word_file = "/usr/share/dict/words"
WORDS = open(word_file).read().splitlines()
print("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
@page {margin: 0;}
th, td { page-break-inside:avoid; page-break-after:auto; width: 150px;max-width: 150px;min-width:150px;}
</style>
</head>
<body>
""")
print('<table class="table">')
print('<thead><tr>')
for i in range(cols):
print('<th id="colTh{i}">Col {i}</th>'.format(i=i))
print('</tr></thead>')
print('<tbody>')
for i in range(rows):
print('<tr>')
for j in range(cols):
if j == 0:
word = 'row {}'.format(i)
else:
word = random.choice(WORDS)
print('<td>{}</td>'.format(word))
print('</tr>')
print('</tbody>')
print('</table>')
print('<script></script>')
print("""
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="test.js"></script>
</body>
</html>
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment