Created
November 5, 2012 01:24
-
-
Save gtracy/4014715 to your computer and use it in GitHub Desktop.
A tiny redirector app that runs on App Engine
This file contains 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
import os | |
import logging | |
from google.appengine.ext import webapp | |
from google.appengine.ext.webapp import util | |
blog_slugs = { | |
'my-post' : '/12/09/', | |
'my-second-post' : '/12/12/' | |
} | |
class MainHandler(webapp.RequestHandler): | |
def get(self,slug=None): | |
if( slug is not None ): | |
if( slug in blog_slugs.keys() ): | |
self.redirect('http://blog.gregtracy.com/%s/%s.html' % (blog_slugs[slug],slug)) | |
else: | |
logging.debug('missed lookup for %s' % slug) | |
self.redirect('http://blog.gregtracy.com') | |
else: | |
self.redirect('http://blog.gregtracy.com') | |
return | |
## end MainHandler | |
def main(): | |
logging.getLogger().setLevel(logging.DEBUG) | |
application = webapp.WSGIApplication([('/(.*)', MainHandler), | |
], | |
debug=True) | |
util.run_wsgi_app(application) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment