Created
May 16, 2018 10:46
-
-
Save ktr0731/255c4d2c1a2b7b153e8758f0a19959c7 to your computer and use it in GitHub Desktop.
短縮 URL 展開してくれる君
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 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