-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificate.py
89 lines (65 loc) · 1.98 KB
/
certificate.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# from __future__ import print_function
import time, sys, webbrowser
if sys.version_info[0]==2:
input = raw_input
import cgi
htmlescape = cgi.escape
else:
import html
htmlescape = html.escape
maxline = 60
browser = True
saveto = 'Certificate.txt'
template = """
%s
===> Oficial Certificate <===
Date: %s
This certifies that:
\t%s
has survived the massive tome:
\t%s
and is now entitled to all privilages therof, including
the right to procced on the lerning how to develop Web
sites, desktop GUIs, scientific models, and assorted apps,
with the posibile assistance of follow-up applications
books such as Programming Python (shameless plug intended).
--Mark Lutz, Instructor
(Note: certificate void where obtained by skipping ahead.)
%s
"""
for c in 'Congratulations!'.upper():
print(c, end=' ')
sys.stdout.flush()
time.sleep(0.25)
print()
date = time.asctime()
name = input('Enter yout name: ').strip() or 'An unknown reader'
sept = '*' * maxline
book = 'Learning Python 5th Edition'
file = open(saveto, 'w')
text = template % (sept, date, name, book, sept)
print(text, file=file)
file.close()
htmlto = saveto.replace('.txt', '.html')
file = open(htmlto, 'w')
tags = text.replace(sept, '<hr>')
tags = tags.replace('===>', '<h1 align=center>')
tags = tags.replace('<===', '</h1>')
tags = tags.split('\n')
tags = ['<p>' if line == ''
else line for line in tags]
tags = ['<i>%s</i>' % htmlescape(line) if line[:1] == '\t'
else line for line in tags]
tags = '\n'.join(tags)
link = '<i><a href="http://www.rmi.net/~lutz">Book support site</a></i>\n'
foot = '<table>\n<td><img src="ora-lp.jpg" hspace=5>\n<td>%s</table>\n' % link
tags = '<html><body bgcolor=beige>' + tags + foot + '</body></html>'
print(tags, file=file)
file.close()
print('[File: %s]' % saveto, end='')
print('\n' * 2, open(saveto).read())
if browser:
webbrowser.open(saveto, new=True)
webbrowser.open(htmlto, new=False)
if sys.platform.startswith('win'):
input('[Pres Enter')