-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallpaper_unsplash.py
41 lines (32 loc) · 966 Bytes
/
wallpaper_unsplash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pathlib import Path
import random
import requests
import datetime
import json
import utils
def get_data():
with open('search-terms.txt') as f:
queries = [line.rstrip('\n') for line in f]
with open('credentials.json') as f:
key = json.load(f)["UNSPLASH_KEY"]
random_choice = random.choice(queries)
print("category: " + random_choice)
params = dict(query=random_choice, orientation='landscape')
endpoint = '/photos/random'
response = requests.get(
'https://api.unsplash.com' + endpoint,
headers={
'Authorization': 'Client-ID ' + key},
params=params
)
return response.json()
def get_wallpapers(wallpaper):
id = str(wallpaper["id"])
url = wallpaper["urls"]["full"]
print(id + ": " + url)
utils.save_image(url)
if __name__ == '__main__':
print(datetime.datetime.now())
get_wallpapers(get_data())
utils.set_wallpaper()
print()