import requests def get_wall(tags): """ get_wall(tags) Grabs a random wallpaper from unsplash.com's random function If any tags are passed in as the message, it will search for images matching those tags """ unsplash_url = "https://source.unsplash.com/3840x2160/?" if len(tags.split()) > 2: search_terms = tags.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 else: url = unsplash_url + tags response = requests.get(url, timeout=8).url if "photo-1446704477871-62a4972035cd" in response: return "Could not find an image for those tags." else: return response