Auto-Generated Github User Page With py-github

June 29, 2010

Update (2010-06-30)

So I got antsy about this and I upgraded to using pystache instead of my homebrew templating system. This was my first run in with mustache, and I have to say I like it, even though I used the bare minimum feature set.

New code is at http://github.com/jmhobbs/jmhobbs.github.com

Github has a cool feature called “Github Pages” that let you host static content on a subdomain of github, e.g. http://jmhobbs.github.com/.

They also provide an auto-generator for project pages that has a nice clean format which I really like. So I decided to make my user page match the look and feel of the project pages. And to boot I wanted to be able have it auto-generate since I want it to be “hands free”, otherwise I’ll forget to update it.

To make this happen I whipped up my template and then grabbed the excellent py-github from Dustin Sallings, which I have used before.

Without furthur ado I’ll just show you the source. It’s not complicated, just some API calls then search replace on a template file. If you want to use it, be sure to get the most recent version from http://github.com/jmhobbs/jmhobbs.github.com.

Throw in a cron job and you are set. Beware of lot’s of “page build” notices from Github though.


except AttributeError:
repo_string = repo_string + ‘


pass

repo_string = repo_string + “

\n”

template = template.replace( ‘<% repos %>‘, repo_string )

ga = “””

“””

if False != settings[‘google_analytics’]:
template = template.replace( ‘<% google_analytics %>‘, ga )
template = template.replace( ‘<% ga_code %>‘, settings[‘google_analytics’] )
else:
template = template.replace( ‘<% google_analytics %>‘, ” )

print “Writing file…”
f = open( ‘index.html’, ‘w’ )
f.write( template )
f.close()

print “Done!”

if __name__ == “__main__”:
main()

Wow. You actually scrolled through all of that. Amazing.

Categories: Geek
Tags: , , , ,

Comments

  1. Nicely done. If you don’t mind, I think I’m going to fork this thing and make a few changes. Specifically:

    I don’t like using GitHub’s web hosting. I love their page builder and love their clean look, I just don’t like having a “magical” branch in my repo that GitHub uses for the page.

    But the clean look is awesome. I think I’m going to take this code and turn it into a project page builder that reads from GitHub and then publishes to a location on my server.

    I’ll see what I can come up with. Nice script though.

  2. john says:

    Cool, let me know if it blows up or anything.

    Also, why don’t you like the Github Pages? It’s free CDN hosting, what’s not to love? Just because it’s a git repo doesn’t mean anything. It’s not much different than Heroku I would think.

  3. john says:

    FYI I cleaned my template mess up with pystache. Ignore the above source code and go to http://github.com/jmhobbs/jmhobbs.github.com for the good stuff.

Leave A Comment

Your email will not be published.