-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownloader.py
195 lines (169 loc) · 6.08 KB
/
Downloader.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import wx.adv
import wx
import praw
import subprocess
import os
import datetime
import random
import ctypes
import xml.etree.ElementTree as ET
import time
import threading
import sys
import urllib.request
TRAY_TOOLTIP = 'Reddit Wallpaper Crawler'
TRAY_ICON = 'Data/icon.png'
CURRENT_PIC = ""
DURATION = 0
STILLALIVE = False
WALLPAPERCHANGED = False
# Starting the API
reddit = praw.Reddit(client_id='EEPkNhcUV4y8gg',
client_secret='OZN1DEPwlM_xConxa3S9dwkpj-c',
user_agent='Wallpaper Dowloader',
username='VegetableBike8',
password='\OY42=h2zk$Zl[!>;gUxc=U}~N+SSUqM')
def WallpaperDownloader(number, Subs, AllWallpaper):
try:
global CURRENT_PIC
todaysSub = Subs[random.randint(0, len(Subs)-1)]
subreddit = reddit.subreddit(todaysSub).hot(limit=10*number)
for submission in subreddit:
if(submission.url not in AllWallpaper and "comment" not in submission.url):
selectedlink = submission.url
now = datetime.datetime.now()
timeRightNow = now.strftime(
"%Y-%m-%d-%H%M")+str(random.randint(1, 1024))
CURRENT_PIC = timeRightNow+".jpg"
with open("Normal/Wallpaper.log", "a") as WallpaperLog:
WallpaperLog.write(
str(selectedlink)+", " + now.strftime("%Y-%m-%d %H:%M")+","+todaysSub+"\n")
urllib.request.urlretrieve(
selectedlink, "Normal\\"+CURRENT_PIC)
ctypes.windll.user32.SystemParametersInfoW(
20, 0, os.getcwd()+"\\Normal\\"+timeRightNow+".jpg", 0)
return True
except:
return False
def InitWallpaper():
global DURATION
# Downloading the image and setting Background
# Extracting data from Configs.xml
# Subs
tree = ET.parse("Data/config.xml")
root = tree.getroot()
Subs = []
for lines in root.find("Subs"):
Subs.append(lines.text)
if(len(Subs) == 0):
Subs = ["wallpapers"]
# Duration
try:
DURATION = int(root.find("Interval").text)
except:
DURATION = 30
# Collecting All Previous Images downloaded
try:
WallpaperLog = open("Normal/Wallpaper.log")
AllWallpaper = []
for lines in WallpaperLog:
plink = lines.split(",")[0]
AllWallpaper.append(plink)
WallpaperLog.close()
AllWallpaper = set(AllWallpaper)
except:
AllWallpaper = set()
# Downloading a new Random Picture
Status = False
Number = 2
while not Status:
Status = WallpaperDownloader(Number, Subs, AllWallpaper)
Number *= 2
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.Append(item)
return item
class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
self.ShowBalloon(title="Welcome to RWC", text="Your timely wallpaper changer", msec=100)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'New Image', self.requestImage)
create_menu_item(menu, 'Add To Favorite', self.MoveToFavorite)
create_menu_item(menu, 'Remove this image and add new', self.DeleteCurrent)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.Icon(path)
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
subprocess.call("cd Data & notepad.exe config.xml", shell=True)
def MoveToFavorite(self, event):
global CURRENT_PIC
str1 = "move /y Normal\\" + CURRENT_PIC+" Favorite\\" + CURRENT_PIC
subprocess.call(str1, shell=True)
self.ShowBalloon(title="Reddit Wallpaper Crawler", text="Image Moved to Favorite Folder", msec=50)
def requestImage(self, event):
global WALLPAPERCHANGED
InitWallpaper()
self.ShowBalloon(title="Reddit Wallpaper Crawler", text="Image Changed", msec=50)
WALLPAPERCHANGED = True
def DeleteCurrent(self, event):
global CURRENT_PIC
global WALLPAPERCHANGED
command = "del /f "+os.getcwd()+"\\Normal\\"+CURRENT_PIC
subprocess.call(command, shell=True)
command = "del /f "+os.getcwd()+"\\Favorite\\"+CURRENT_PIC
subprocess.call(command, shell=True)
InitWallpaper()
self.ShowBalloon(title="Reddit Wallpaper Crawler", text="Image Changed", msec=50)
WALLPAPERCHANGED = True
def on_exit(self, event):
global STILLALIVE
STILLALIVE = True
wx.CallAfter(self.Destroy)
self.frame.Close()
def IntervalChange():
global DURATION
global STILLALIVE
global WALLPAPERCHANGED
while(True):
InitWallpaper()
i = 0
while(i < DURATION*6):
time.sleep(10)
i += 1
if(STILLALIVE):
return
if(WALLPAPERCHANGED):
i = 0
WALLPAPERCHANGED = False
class App(wx.App):
def OnInit(self):
frame = wx.Frame(None)
self.SetTopWindow(frame)
TaskBarIcon(frame)
return True
def main():
ImageChangerAfterInterval = threading.Thread(target=IntervalChange)
ImageChangerAfterInterval.start()
app = App(False)
app.MainLoop()
ImageChangerAfterInterval.join()
if __name__ == '__main__':
PATH = sys.argv[1]
# Making Directory if not present
if(not os.path.isdir(PATH)):
os.mkdir(PATH)
os.chdir(PATH)
if(not os.path.isdir(PATH+"\\Favorite")):
os.mkdir(PATH+"\\Favorite")
if(not os.path.isdir(PATH+"\\Normal")):
os.mkdir(PATH+"\\Normal")
main()