""" Generate a simple class completion certificate: printed to the console, and saved in auto-opened text and HTML files. Run from a console, and print saved output files if desired. Works on all PCs, but may require manual opens on smartphones. """ import time, sys, html, os maxline = 60 # Text separator lines browser = True # Display in a browser? saveto = 'Certificate' # Output filenames prefix # Template values SEPT = '*' * maxline DATE = time.strftime('%A, %b %d, %Y, %I:%M %p') NAME = input('Please enter your name: ').strip() or 'An unknown reader' BOOK = 'Learning Python, 6th Edition' SITE = 'https://learning-python.com' # For icon, image, link # F-string templates work for preset in-code references texttext = f""" {SEPT} ⭐️ Official Certificate ⭐️ Date: {DATE} This certifies that: \t{NAME} Has survived the massive tome: \t{BOOK} And is now entitled to all privileges thereof, including the right to proceed on to learning how to develop websites, desktop GUIs, scientific models, smartphone apps, and anything else that the future of computing may hold. --Your humble 🐍 instructor (Note: void where obtained by skipping ahead.) {SEPT} """ # Interact, setup for c in 'Congratulations!'.upper() + '👏' * 3: print(c, end=' ') sys.stdout.flush() # Else some shells wait for \n time.sleep(0.25) # Reveal message slowly for fun print(); time.sleep(3) # Make text-file version textto = saveto + '.txt' fileto = open(textto, 'w', encoding='utf8') print(texttext, file=fileto) fileto.close() # Start HTML: replace text markers with tags htmltext = texttext.replace(SEPT, '
' elif line[:1] == '\t': line = f"{' ' * 4}{html.escape(line[1:])}" # 3.6+ linemods.append(line) htmltext = '\n'.join(linemods) # Ignorable HTML bits (mind the {{ and }} escapes) preamble = f'''
| Book support site |