Skip to content

Instantly share code, notes, and snippets.

@alxhill
Created September 7, 2011 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alxhill/1201212 to your computer and use it in GitHub Desktop.
Save alxhill/1201212 to your computer and use it in GitHub Desktop.
Statify - turn a dynamic page static
#!/usr/bin/python
import sys
import urllib
import os
def statify(baseurl, pages, folder, home=True):
os.mkdir(folder)
baseurl = baseurl if baseurl[-1] is "/" else baseurl + "/"
full_pages = [ baseurl + page for page in pages ]
for i, page in enumerate(full_pages):
urllib.urlretrieve(page, folder + "/" + pages[i])
if home:
urllib.urlretrieve(baseurl, folder + "/index.html")
### - Example Use - ###
def main():
pages = ["about.html", "contact.html", "portfolio.html", "online.html", "clients.html"]
base = "http://example.com/"
folder = sys.argv[1] if sys.argv[1] else "statified"
statify(base, pages, folder)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment