Created
February 27, 2011 23:13
-
-
Save vim13/846678 to your computer and use it in GitHub Desktop.
flic.krショートURLのIDからサムネイル取得
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
class FlickrApi: | |
def b58decode(self, s): | |
alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' | |
num = len(s) | |
decoded = 0 | |
multi = 1 | |
for i in reversed(range(0, num)): | |
decoded = decoded + multi * ( alphabet.index( s[i] ) ) | |
multi = multi * len(alphabet) | |
return decoded | |
def flickrApi(self, photo_id, flickr_api_key): | |
dec_photo_id = self.b58decode(photo_id) | |
uri = 'http://www.flickr.com/services/rest?method=flickr.photos.getInfo&format=json&api_key=%s&photo_id=%s' % (flickr_api_key, dec_photo_id) | |
print uri | |
f = urllib2.urlopen(uri).read() | |
farm = re.search('"farm":([0-9])', f).group(1) | |
server = re.search('"server":"([0-9]+)"', f).group(1) | |
my_id = re.search('"id":"([0-9]+)"', f).group(1) | |
secret = re.search('"secret":"([0-9a-z]+)"', f).group(1) | |
res = 'http://farm%s.static.flickr.com/%s/%s_%s.jpg' % (farm, server, my_id, secret) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment