def download_wallpaper(width=1920, height=1080): """Return the downloaded wallpaper file name""" # available categories categories = get_categories() category = random.choice(categories) # image url base_url = "https://source.unsplash.com" tags = get_tags() collection = 1598183 #image_url = '{}/{}x{}?{},{}'.format(base_url, # str(width), str(height), category, tags) image_url = '{}/{}/{}/{}x{}'.format(base_url, "collection", str(collection), str(width), str(height)) #image_url = "https://source.unsplash.com/collection/1598187/1920x1080" # landscapes #image_url = "https://source.unsplash.com/collection/1598189/1920x1080" # my first collection (everything) #image_url = "https://source.unsplash.com/collection/1598183/1920x1080" # download image try: wallpaper_name = 'wallpaper.jpg' response = download_image(image_url, base_path("/" + wallpaper_name)) except: # if previously download wallpaper not exist if not os.path.isfile(base_path("/" + wallpaper_name)): wallpaper_name = "default-wallpaper.jpg" # show the default wallpaper log('Unable to download wallpaper') return base_path("/" + wallpaper_name)
def get_tags(): """Fetch user defined tags""" file = base_path('/configs/tag') if not os.path.isfile(file): file_handler = open(file, 'w') file_handler.close() file_handler = open(file, 'r') stored_tags = file_handler.readline() file_handler.close() if bool(stored_tags): return stored_tags else: return ""
def get_categories(): """Fetch user defined categories""" file = base_path('/configs/category') if not os.path.isfile(file): file_handler = open(file, 'w') file_handler.close() file_handler = open(file, 'r') stored_categories = file_handler.readline() file_handler.close() category_list = str(stored_categories).split(",") if bool(stored_categories): return category_list else: return str(categories).split(",")
def download_wallpaper(width=1600, height=900): """Return the downloaded wallpaper file name""" # available categories categories = get_categories() category = random.choice(categories) # image url base_url = "https://source.unsplash.com" tags = get_tags() image_url = '{}/{}x{}?{},{}'.format(base_url, str(width), str(height), category, tags) # download image try: wallpaper_name = 'wallpaper.jpg' response = download_image(image_url, base_path("/" + wallpaper_name)) except: # if previously download wallpaper not exist if not os.path.isfile(base_path("/" + wallpaper_name)): wallpaper_name = "default-wallpaper.jpg" # show the default wallpaper log('Unable to download wallpaper') return base_path("/" + wallpaper_name)
def set_tags(input_tags): """set user defined tags""" file_handler = open(base_path('/configs/tag'), 'w') file_handler.write(str(input_tags)) file_handler.close()
def set_categories(input_categories): """set user defined categories""" file_handler = open(base_path('/configs/category'), 'w') file_handler.write(str(input_categories)) file_handler.close()
def set_tags(input_tags): """Set user defined tags""" with open(base_path('/configs/tag'), 'w') as file_handler: file_handler.write(str(input_tags))
def set_categories(input_categories): """set user defined categories""" with open(base_path('/configs/category'), 'w') as file_handler: file_handler.write(str(input_categories))