Created
April 19, 2013 22:54
-
-
Save shriphani/5423800 to your computer and use it in GitHub Desktop.
using the requests module to resolve urls
This file contains hidden or 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
| '''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