Skip to content

Instantly share code, notes, and snippets.

@ktr0731
Created May 16, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktr0731/255c4d2c1a2b7b153e8758f0a19959c7 to your computer and use it in GitHub Desktop.
Save ktr0731/255c4d2c1a2b7b153e8758f0a19959c7 to your computer and use it in GitHub Desktop.
短縮 URL 展開してくれる君
import sys
import requests
# default arg is the demo url
def req(url='https://bit.ly/1cY78RZ'):
res = requests.head(url)
if int(res.status_code / 100) != 3:
return res.url
else:
return req(res.headers['Location'])
def main():
if len(sys.argv) == 2:
print(req(sys.argv[1]))
else:
print(req())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment