Skip to content

Instantly share code, notes, and snippets.

@jplattel
Created December 30, 2013 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplattel/8181849 to your computer and use it in GitHub Desktop.
Save jplattel/8181849 to your computer and use it in GitHub Desktop.
Mobypicture export trough their API.
#!/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