forked from PDX-Capstone-Team-C/test-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.py
More file actions
executable file
·52 lines (45 loc) · 1.32 KB
/
generate.py
File metadata and controls
executable file
·52 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import uuid
import random
import sys
import os
import errno
# Script to generate N HTML pages with random data
# Usage: python generate N directory
# HTML files will be placed in /vagrant/web/html/random/[directory]
# With vagrant web, can be accessed via 10.10.10.10/random
def main(argv):
N = int(sys.argv[1])
for i in range(1, N):
directory = r'/vagrant/web/html/random/' + sys.argv[2]
checkDir(directory)
filename = str(i) + '.html'
genPage(directory + '/' + filename, i)
genPage(directory + '/' + 'index.html', N)
def checkDir(directory):
try:
os.makedirs(directory)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
def genPage(filename, i):
file = open(filename, 'w')
file.write('<!DOCTYPE html>')
file.write('<html>\n')
file.write('<body>\n')
if i > 1:
tag = '<a href="{0}.html">{0}</a>'.format(i - 1)
file.write(tag + '\n')
genContent(file)
file.write('</body>\n')
file.write('</html>\n')
file.close()
def genContent(file):
random.seed()
for i in range (1, random.randint(3, 15)):
file.write('<p>\n')
for j in range (1, random.randint(20, 100)):
x = uuid.uuid4()
file.write(str(x) + '<br>\n')
file.write('</p>\n')
if __name__ == '__main__':
main(sys.argv[1:])