Skip to content

Instantly share code, notes, and snippets.

@acrymble
Created July 5, 2011 19:50
Show Gist options
  • Select an option

  • Save acrymble/1065736 to your computer and use it in GitHub Desktop.

Select an option

Save acrymble/1065736 to your computer and use it in GitHub Desktop.
Python wrap string in HTML
# 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