From d7287622b9c11a859533948d746ef5235da93196 Mon Sep 17 00:00:00 2001 From: Tristan Le Chanony Date: Mon, 7 Jan 2019 13:50:35 +0100 Subject: [PATCH] Improve unsplash mode --- bot.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index a0b80fb..d1097d2 100755 --- a/bot.py +++ b/bot.py @@ -69,7 +69,19 @@ def post_img_local(mastodon, text, log, config): return media_dict; def post_unsplash_random_image(mastodon, log, config): - response = requests.get('https://api.unsplash.com/photos/random?client_id=03ad5bfbaa0acd6c96a728d425e533683ec25e5fb7fcf99f6461720b3d0d75a1') + collection_url = get_parameter("collection_url", config) + unsplash_client_id = get_parameter("unsplash_client_id", config) + collecion_file = open(collection_filepath,'r') + collections = json.loads(collecion_file.read()) + collecion_file.close() + + count_collection = len(collections)-1 + if count_collection > -1: + id_collection = randint(0,count_collection) + collection_url="&collections="+str(collections[id_collection]) + else: + collection_url='' + response = requests.get("https://api.unsplash.com/photos/random?client_id="+unsplash_client_id+collection_url) randim_json = json.loads(response.text) randim_url = "{}&q=85&crop=entropy&cs=tinysrgb&w=2048&fit=max".format(randim_json['urls']['raw'])