dragon-bot/app/wallpaper.py

29 lines
734 B
Python

import requests
def get_wall(message):
unsplash_url = "https://source.unsplash.com/3840x2160/?"
if len(message.split()) > 2:
search_terms = message.split()[1:]
# Turn search_terms into strings separated by commas
joined_terms = ','.join(search_terms)
# Add those comma separated strings onto the end of the URL variable
url = unsplash_url + joined_terms
elif len(message.split()) > 1:
term = message.split()[1]
url = unsplash_url + term
else:
url = unsplash_url
response = requests.get(url).url
if 'photo-1446704477871-62a4972035cd' in response:
return "Could not find an image for those tags."
else:
return response