Created
December 30, 2013 13:00
-
-
Save jplattel/8181849 to your computer and use it in GitHub Desktop.
Mobypicture export trough their API.
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/local/bin/python | |
import os | |
import urllib | |
import simplejson as json | |
import time | |
#params | |
def fetchPage(i): | |
url = "https://api.mobypicture.com/" | |
apikey = "" | |
username = "" | |
params = urllib.urlencode({"action": "getUserMedia", "key": apikey, "username": username, "format": "json", "page": i}) | |
u = urllib.urlopen(url + "?" + params) | |
response = json.loads(u.read()) | |
l = [] | |
for result in response['results']: | |
#print result['title'] | |
#print result['created_on'] | |
g = [result['title'],result['media']['url_full'], result['created_on']] | |
l.append(g) | |
print "Fetching page: " + str(i) | |
return l | |
def getImage(url, name): | |
image = urllib.urlopen(url).read() | |
name = name.replace('/','_') | |
f = open(name, "wb") | |
f.write(image) | |
f.close() | |
print "Saving picture: " + name | |
def paging(i): | |
total = [] | |
for i in range(1,i): | |
data = fetchPage(i) | |
for item in data: | |
total.append(item) | |
time.sleep(1) | |
return total | |
photos = paging(35) | |
for photo in photos: | |
getImage(photo[1], photo[2] + " " + photo[0] + ".jpg") | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment