Created
January 16, 2011 06:39
-
-
Save alice1017/781613 to your computer and use it in GitHub Desktop.
短縮URLサービスux.nuを使ってurlを短縮
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
| #!/usr/bin/python | |
| #coding:utf-8 | |
| import urllib | |
| import sys | |
| import json | |
| def getlink(site): | |
| url = "http://ux.nu/api/short" | |
| param = urllib.urlencode({"url":site}) | |
| res = urllib.urlopen(url+"?"+param).read() | |
| return json.loads(res) | |
| def expandlink(site): | |
| url = "http://ux.nu/hugeurl" | |
| params = urllib.urlencode({"format": "json","url": site}) | |
| return json.loads(urllib.urlopen(url+"?"+params).read()) | |
| if __name__ == "__main__": | |
| try: | |
| site = sys.argv[1] | |
| if site[0:13] == "http://ux.nu/": | |
| print expandlink(site)["exp"] | |
| else: | |
| print getlink(site)["data"]["url"] | |
| except: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://discord.gg/ETM3nJ75f9