Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 63 lines (50 sloc) 1.62 kb
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
#!/usr/bin/env python

# http://xkcd.com/353/
import urllib
import urllib2
import shutil
import zipfile
import os

# Welcome the user
print "I'm going to ask you for some information about your theme.\n"
print "You have to give your theme a name but you can leave the others blank if you want.\n"
print "Let's get started.\n"

# Get your theme name
name = raw_input('Name? ')

# You need to provide a unique name for the theme
while not name or os.path.exists(name) or os.path.exists(name + '.zip'):
    print "\nYou need a name for your theme that doesn't match existing files or directories.\n\n"
    name = raw_input('Name? ')

# Get the rest of your customizations
slug = raw_input('Slug? ')
author = raw_input('Author? ')
author_uri = raw_input('Author URI? ')
description = raw_input('Description? ')

# And a few defaults
generate = 1
generate_submit = 'Generate'

# Parse the inputs
data = {
    'underscoresme_name': name,
    'underscoresme_slug': slug,
    'underscoresme_author': author,
    'underscoresme_author_uri': author_uri,
    'underscoresme_description': description,
    'underscoresme_generate': generate,
    'underscoresme_generate_submit': generate_submit
}

# Setup the request data
body = urllib.urlencode(data)
headers = {'User-Agent': '_sh'}

# Make the request
request = urllib2.Request('http://underscores.me', body, headers)
response = urllib2.urlopen(request)

# Save the zip file
target = open(name + '.zip', 'wb')
shutil.copyfileobj(response.fp, target)
target.close()

# Unzip it
zip = zipfile.ZipFile(name + '.zip')
zip.extractall()

# Delete the zip file
os.remove(name + '.zip')
Something went wrong with that request. Please try again.