Created
July 5, 2011 19:50
-
-
Save acrymble/1065736 to your computer and use it in GitHub Desktop.
Python wrap string in HTML
This file contains hidden or 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
| # Given name of calling program, a url and a string to wrap, | |
| # output string in html body with basic metadata | |
| # and open in Firefox tab. | |
| def wrapStringInHTML(program, url, body): | |
| import datetime | |
| from webbrowser import open_new_tab | |
| now = datetime.datetime.today().strftime("%Y%m%d-%H%M%S") | |
| filename = program + '.html' | |
| f = open(filename,'w') | |
| wrapper = """<html> | |
| <head> | |
| <title>%s output - %s</title> | |
| </head> | |
| <body><p>URL: <a href=\"%s\">%s</a></p><p>%s</p></body> | |
| </html>""" | |
| whole = wrapper % (program, now, url, url, body) | |
| f.write(whole) | |
| f.close() | |
| #Mac version, insert following line as above. | |
| #filename = 'file:///Users/username/Desktop/programming-historian/' + filename | |
| open_new_tab(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment