Created
June 3, 2019 01:05
-
-
Save zeropwn/fdfd7abb609a78df047e0012147729b7 to your computer and use it in GitHub Desktop.
Non-Ratelimited Unsplash.com Image Search Client
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
#!/usr/bin/python3 | |
import json | |
import requests | |
import argparse | |
import urllib.parse | |
SEARCH_URL = "https://unsplash.com/napi/search/photos" | |
p = argparse.ArgumentParser(description="Non-Ratelimited Unsplash API Client") | |
p.add_argument('-s', help="search query") | |
p.add_argument('-p', help="page") | |
args = p.parse_args() | |
if args.p: | |
page = args.p | |
else: | |
page = 1 | |
search = args.s | |
enc_search = urllib.parse.quote(search) | |
options = { | |
'query': enc_search, | |
'per_page': 30, | |
'page': args.p | |
} | |
r = requests.get(SEARCH_URL, params=options) | |
json = r.json() | |
print("[*] Found {} results with a total of {} pages.".format(json['total'], json['total_pages'])) | |
print("[*] Printing 30 results from page {}\n".format(page)) | |
for photo in json['results']: | |
photo_id = photo['id'] | |
url = photo['urls']['raw'] | |
desc = photo['description'] | |
preview = photo['urls']['small'] | |
if(desc is None): | |
desc = photo['alt_description'] | |
print('--------------------------------------------------------------') | |
print("\033[1m\033[92mDescription: \033[0m", desc) | |
print("\033[1m\033[92mPreview URL: \033[0m", preview) | |
print("\033[1m\033[92mFull Resolution URL: \033[0m", url) | |
print('--------------------------------------------------------------') | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment