Skip to content

Instantly share code, notes, and snippets.

@shriphani
Created April 19, 2013 22:54
Show Gist options
  • Save shriphani/5423800 to your computer and use it in GitHub Desktop.
Save shriphani/5423800 to your computer and use it in GitHub Desktop.
using the requests module to resolve urls
'''Resolve a url'''
import argparse
import requests
def resolve_url(url):
return (requests.get(url)).url
if __name__ == '__main__':
def parse_cmdline_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--forums-list',
dest = 'forums_list',
help = 'Location of forums list'
)
return parser.parse_args()
parsed = parse_cmdline_args()
with open(parsed.forums_list, 'r') as forums_list_handle:
for url in forums_list_handle:
try:
print resolve_url(url.strip())
except requests.exceptions.ConnectionError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment