-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwallpaper.py
More file actions
115 lines (99 loc) · 3.36 KB
/
Copy pathwallpaper.py
File metadata and controls
115 lines (99 loc) · 3.36 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import ctypes
import os
from bs4 import BeautifulSoup
import time
from urllib.error import HTTPError
import urllib.request
from urllib.request import urlretrieve
import re
import errno
import shutil
import random
import sys
def downloadImage():
wcount =0
try:
wallpaperLinks=WallpaperAddress()
#print("1")
for wallpaperLink in wallpaperLinks:
#print("2")
urldownload = fetchPhotos("http://www.santabanta.com"+wallpaperLink)
#print(urldownload)
#print(wcount)
#fetchPhotos(correctlink)
#fetchPhotos(correctlink)
urlretrieve(urldownload,wallpapercount(wcount))
print("Wallpaper Downloaded : ",wcount)
wcount = wcount + 1
except FileNotFoundError as err: #If something Wrong with Local Path
print(err)
except HTTPError as err: # IF something Wrong with HTTP Downloading
print(err)
def ChangeWallpaper():
#wcount = 0
while True:
SPI_SETDESKWALLPAPER = 20
try:
lis=WallpaperAddress()
list_Length = len(lis)
wcount=random.randint(0,list_Length-1)
print(wcount)
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,wallpapercount(wcount),0)
print("**********************Wallpaper Changed********************")
#wcount = wcount + 1
time.sleep(900)
except FileNotFoundError as err:
print(err)
def wallpapercount(wcount):
#wcount = wcount + 1
return ("C:/Users/dev/Desktop/wallpapers/" + str(wcount) +".jpg")
def WallpaperAddress():
user_url = input("Enter URl : ")
if(user_url == ""):
url="http://www.santabanta.com/wallpapers/categories/0/?order=popular"
else:
url=user_url
#url=urllib.request.urlopen("http://www.santabanta.com/wallpapers/indian-celebrities(f)/2/")
url=urllib.request.urlopen(url)
soup=BeautifulSoup(url,"html.parser")
lst = []
for link in soup.find_all('a'):
if link.has_attr('href'):
if '/photos' in link['href']:
#print(link['href'])
#print(type(link))
lst.append(link['href'])
print("***************Returning URLs List****************")
return lst
def fetchPhotos(url):
#print(url)
url=urllib.request.urlopen(url)
#print(url)
soup=BeautifulSoup(url,"html.parser")
url =soup.find_all('img',{"src" : re.compile('http://media1.santabanta.com/full1.*')})
#print(url)
for i in url:
print("**************Sending Individual Photo URL**************")
return (i.get('src'))
#print(type(url))
def deleteExisting():
try:
shutil.rmtree("C:/Users/dev/Desktop/wallpapers/")
print("*********************Existing Wallpaper Folder Deleted*******************************")
time.sleep(2)
except OSError:
pass
def createFolder():
directory = "C:/Users/dev/Desktop/wallpapers/"
if not os.path.exists(directory):
try:
os.makedirs(directory)
print("*********************New Wallpaper Folder Created****************")
time.sleep(2)
except OSError as e:
if e.errorno != errorno.EEXIST:
raise
deleteExisting()
createFolder()
downloadImage()
ChangeWallpaper()