Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# coding:utf-8
import sys
import re
from urllib2 import urlopen as U, Request as R
from json import loads as J
API_KEY = "ここはGoogleのAPIを取得して使う"
API = "" + API_KEY
# ここに短縮化したいURLをリスト形式で置いておく
URLarray = ['','']
for URL in URLarray:
if re.match('http://goo\.gl/.+', URL):
print J(U(API + '?shortUrl=%s' % URL).read())['longUrl']
print J(U(R(API, '{"longUrl":"%s"}' % URL, {'Content-Type': 'application/json'})).read())['id']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.