Skip to content

Instantly share code, notes, and snippets.

@alice1017
Created January 16, 2011 06:39
Show Gist options
  • Select an option

  • Save alice1017/781613 to your computer and use it in GitHub Desktop.

Select an option

Save alice1017/781613 to your computer and use it in GitHub Desktop.
短縮URLサービスux.nuを使ってurlを短縮
#!/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
@coffeejerry491
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment