Skip to content

Instantly share code, notes, and snippets.

@starenka
Created August 20, 2012 21:38
Show Gist options
  • Save starenka/3408133 to your computer and use it in GitHub Desktop.
Save starenka/3408133 to your computer and use it in GitHub Desktop.
shows full redirect path for given url
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from flask import Flask
import requests
app = Flask(__name__)
app.debug = False
@app.route('/url=<path:uri>/')
def show_redirects(uri):
resp = requests.get(urllib2.unquote(uri).replace(':/', '://'))
urls = [one.url for one in resp.history] + [resp.url]
ret = '<html><head><link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"></head><body>'
ret += ''.join(map(lambda x: '<li><h2><a href="%s">%s</a><h2></li>' % (x,x), urls))
return '<div class="hero-unit"><ol>%s</ol></div></body></html>' % ret
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment