Last active
August 31, 2017 08:35
-
-
Save MartinThoma/056183bc0862a787a8d4e8fe57e51f3f to your computer and use it in GitHub Desktop.
Generate a HTML file with a big table.
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 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