-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.py
61 lines (41 loc) · 1.53 KB
/
html.py
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
53
54
55
56
57
58
59
60
61
#! usr/bin/env python3
# formats received string into content of an html page, then displays it in a browser
# To USE: import html, then send content, which must be a string, to html.make_html()
# import html
# html.make_html('Hello, World!')
# html.make_html(my_string_content)
import os
import webbrowser
def make_header():
doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n'
header = doctype + '<html><head>\n<title>My Title</title>\n</head>\n'
return header
def make_body(content):
center = '<div align="center">\n'
table = '<table width ="900"><tr><td>\n'
heading = '<h2>My Very Own Heading</h2>\n'
end_table = '</td></tr></table>\n'
body = '<body>' + center + table + heading + content + end_table + '</div></body>\n'
return body
def make_end():
return '</html>'
# use these to format text before sending it to html.make_html()
def para(text):
paragraph = '<p>' + text + '</p>'
return paragraph
def color(text2, coloroftext):
coloredtext = '<font color="' + coloroftext + '">' + text2 + '</font>'
return coloredtext
# the MAIN method
def make_html(results):
path = os.getcwd()
with open('results.html', 'w+') as html:
assembled = make_header()
assembled += make_body(results)
assembled += make_end()
html.write(assembled)
html.close()
my_url = 'file:///' + path + '/results.html'
webbrowser.open_new(my_url)
test = para('Hello, ' + color('World!', 'red'))
make_html(test)