-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdailyPinkbikeWallpaperWindows10.py
39 lines (30 loc) · 1.06 KB
/
dailyPinkbikeWallpaperWindows10.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
#!/usr/bin/env python
import requests
from bs4 import BeautifulSoup
import re
import os
import ctypes
import sys
r = requests.get("https://www.pinkbike.com/")
data = r.text
soup = BeautifulSoup(data, "lxml")
# retrieve link for PoD
podLink = soup.find_all('a', attrs={'href': re.compile("^(https:\/\/www.pinkbike.com\/photo\/[0-9]*\/$)")})[0].get('href')
# extract number for pod
photoNum = re.compile("([0-9]+)").findall(podLink)[0]
#pinkbike high res download url = lp1.pinkbike.org/p0pb(image #)/(image #).jpg
urlStart = "https://lp1.pinkbike.org/p0pb"
urlEnd = ".jpg"
downloadURL = urlStart + photoNum + '/' + photoNum + urlEnd
r2 = requests.get(downloadURL)
if getattr(sys, 'frozen', False):
# frozen
dir_path = os.path.dirname(sys.executable)
else:
# unfrozen
dir_path = os.path.dirname(os.path.realpath(__file__))
file_location = dir_path + '\\' + 'PinkbikeBackground.jpg'
# Save image to file named "PinkbikeBackground.jpg"
open(file_location, 'wb').write(r2.content)
# Set background
ctypes.windll.user32.SystemParametersInfoW(20, 0, file_location, 3)