Last active
August 29, 2015 14:11
-
-
Save shiplunc/0a266849526c2f062fb5 to your computer and use it in GitHub Desktop.
List all the image licensed by you. You need to provide access token
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
import json | |
import sys | |
import urllib2 as ul | |
from itertools import count | |
import urllib | |
from urlparse import urlparse, urlunparse | |
def build_url(**qs): | |
params = {'fields': 'data(id,download_time,image/id),total_count', | |
'page': 1, | |
'per_page': 200} | |
params.update(qs) | |
url_tuple = ('https', | |
'api.shutterstock.com', | |
'/v2/images/licenses', | |
'', | |
urllib.urlencode(params), | |
'') | |
return urlunparse(url_tuple) | |
def main(access_token): | |
for page in count(1): | |
final_url = build_url(access_token=access_token, page=page) | |
print >> sys.stderr, "Processing page %s" % page | |
urlh = ul.urlopen(final_url) | |
resp_dict = json.load(urlh) | |
urlh.close() | |
liccount = len(resp_dict['data']) | |
print "Number of licenses found = %s" % liccount | |
if liccount == 0: | |
break | |
else: | |
for i in resp_dict["data"]: | |
print "%s\t%s\t%s" % (i['image']['id'], i['id'], i['download_time']) | |
if __name__ == '__main__': | |
if len(sys.argv) == 2: | |
main(sys.argv[1]) | |
else: | |
print >> sys.stderr, "Program requires exactly one parameter access token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment