Created
January 2, 2017 20:10
-
-
Save jplattel/ea828fe40dfeb1e8b24b99aa56e8ed7f to your computer and use it in GitHub Desktop.
A simple script to pull all my latest Mobypicture photos
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 = "<YOUR_API_KEY_HERE>" | |
params = urllib.urlencode({"action": "getUserMedia", "key": apikey, "username": "jplattel", "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 = 'fotos/' + 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(15) | |
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