Compare commits
No commits in common. "main" and "python" have entirely different histories.
BIN
Changer.exe
BIN
Changer.exe
Binary file not shown.
184
Changer.py
Normal file
184
Changer.py
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
import wx
|
||||||
|
from glob import glob
|
||||||
|
from os import remove, getcwd, mkdir, chdir
|
||||||
|
from os.path import isfile, getsize, isdir
|
||||||
|
from subprocess import Popen, CREATE_NEW_CONSOLE, DETACHED_PROCESS
|
||||||
|
|
||||||
|
chdir("\\".join(__file__.split("\\")[0:-1]))
|
||||||
|
ids = {}
|
||||||
|
CONFIG = ".config"
|
||||||
|
HISTORY = ".history"
|
||||||
|
DESIGN = {
|
||||||
|
"Interval Text": (10, 13),
|
||||||
|
"Interval": (10, 30),
|
||||||
|
"Save": (11, 63),
|
||||||
|
"Hidden": (10, 93),
|
||||||
|
"Safe Mode": (10, 123),
|
||||||
|
"Clear Cache": (10, 150),
|
||||||
|
"Cache Information": (120,153),
|
||||||
|
"Clear History": (10, 180),
|
||||||
|
"History Information": (120,183),
|
||||||
|
"Refresh": (10, 210),
|
||||||
|
"Start": (10, 240)
|
||||||
|
}
|
||||||
|
|
||||||
|
def integrity_check():
|
||||||
|
for i in [1]:
|
||||||
|
if not isfile(CONFIG):
|
||||||
|
pass
|
||||||
|
elif len(open(CONFIG, "r").read().split()) < 4:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
open(CONFIG, "w").write("600\n1\n0\n1")
|
||||||
|
print(CONFIG + " is missing")
|
||||||
|
print("generating " + CONFIG + " with default value of\n Interval = 600 seconds\n Save Wallpapers = True\n Start Hidden = False\n Approximate Time = True")
|
||||||
|
if not isfile(HISTORY):
|
||||||
|
open(HISTORY, "w").write("")
|
||||||
|
print(HISTORY + " is missing")
|
||||||
|
print("generating " + HISTORY)
|
||||||
|
if not isdir(".\\Images"):
|
||||||
|
mkdir(".\\Images")
|
||||||
|
print(getcwd() + "\\Images is missing")
|
||||||
|
print("generating " + getcwd() + ".\\Images")
|
||||||
|
|
||||||
|
class ChangerUI(wx.Frame):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kw):
|
||||||
|
super(ChangerUI, self).__init__(*args, **kw)
|
||||||
|
|
||||||
|
self.InitUI()
|
||||||
|
|
||||||
|
def InitUI(self):
|
||||||
|
|
||||||
|
self.itxt = wx.StaticText(self, pos=DESIGN["Interval Text"], label="Interval:")
|
||||||
|
|
||||||
|
self.Intl = wx.TextCtrl(self, pos=DESIGN["Interval"], style=wx.TE_PROCESS_ENTER, size=(100, 24))
|
||||||
|
self.Intl.SetValue(open(CONFIG, "r").read().split()[0])
|
||||||
|
ids[self.Intl.GetId()] = "Interval"
|
||||||
|
|
||||||
|
self.Save = wx.CheckBox(self, pos=DESIGN["Save"], label="Save Wallpapers")
|
||||||
|
ids[self.Save.GetId()] = "Save"
|
||||||
|
self.Save.SetValue(int(open(CONFIG, "r").read().split()[1]))
|
||||||
|
|
||||||
|
self.Hd = wx.CheckBox(self, pos=DESIGN["Hidden"], label="Start Hidden")
|
||||||
|
ids[self.Hd.GetId()] = "Hidden"
|
||||||
|
self.Hd.SetValue(int(open(CONFIG, "r").read().split()[2]))
|
||||||
|
|
||||||
|
self.Ap = wx.CheckBox(self, pos=DESIGN["Safe Mode"], label="Safe Mode")
|
||||||
|
ids[self.Ap.GetId()] = "Safe"
|
||||||
|
self.Ap.SetValue(int(open(CONFIG, "r").read().split()[3]))
|
||||||
|
|
||||||
|
self.cl = wx.Button(self, label="Clear Cache", pos=DESIGN["Clear Cache"], size=(100, 28))
|
||||||
|
ids[self.cl.GetId()] = "Clear Cache"
|
||||||
|
self.clh = wx.Button(self, label="Clear History", pos=DESIGN["Clear History"], size=(100, 28))
|
||||||
|
ids[self.clh.GetId()] = "Clear History"
|
||||||
|
self.st = wx.Button(self, label="Start", pos=DESIGN["Start"], size=(100, 28))
|
||||||
|
ids[self.st.GetId()] = "Start"
|
||||||
|
self.rf = wx.Button(self, label="Refresh", pos=DESIGN["Refresh"], size=(100, 28))
|
||||||
|
ids[self.rf.GetId()] = "Refresh"
|
||||||
|
|
||||||
|
self.cinf = wx.StaticText( self,
|
||||||
|
label= str(int(sum([getsize(i) for i in glob("./Images/*.*")]) / 1024 / 10.24) / 100) + " MB, " + str(len(glob("./Images/*.*"))) + " Files",
|
||||||
|
pos=DESIGN["Cache Information"])
|
||||||
|
ids[self.cinf.GetId()] = "Cache Information"
|
||||||
|
self.hinf = wx.StaticText( self,
|
||||||
|
label= str(len(open(HISTORY, "r").read().split())) + " Entries",
|
||||||
|
pos=DESIGN["History Information"])
|
||||||
|
ids[self.hinf.GetId()] = "History Information"
|
||||||
|
|
||||||
|
self.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnPress)
|
||||||
|
self.Bind(wx.EVT_CHECKBOX, self.OnPress)
|
||||||
|
self.Bind(wx.EVT_FSWATCHER, self.DirChanged)
|
||||||
|
|
||||||
|
self.SetSize((self.cinf.GetSize().x + 140, DESIGN["Start"][1] + 70))
|
||||||
|
self.SetTitle('Changer')
|
||||||
|
self.Centre()
|
||||||
|
|
||||||
|
def DirChanged(self, e):
|
||||||
|
self.cinf.SetLabel(str(int(sum([getsize(i) for i in glob("./Images/*.*")]) / 1024 / 10.24) / 100) + " MB, " + str(len(glob("./Images/*.*"))) + " Files")
|
||||||
|
|
||||||
|
def OnEnter(self, e):
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Interval":
|
||||||
|
try:
|
||||||
|
float(self.Intl.GetValue())
|
||||||
|
fr = open(CONFIG, "r")
|
||||||
|
c = fr.read().split()
|
||||||
|
fr.close()
|
||||||
|
fw = open(CONFIG, "w")
|
||||||
|
c[0] = self.Intl.GetValue()
|
||||||
|
fw.write("\n".join(c))
|
||||||
|
fw.close()
|
||||||
|
except:
|
||||||
|
print("Invalid Value!")
|
||||||
|
self.Intl.SetValue(open(CONFIG, "r").read().split()[0])
|
||||||
|
|
||||||
|
def OnPress(self, e):
|
||||||
|
if ids[e.GetId()] == "Clear Cache":
|
||||||
|
for i in [i for i in glob("./Images/*.*") if i.split(".")[-1] in ["jpg", "jpeg", "png"]]:
|
||||||
|
remove(i)
|
||||||
|
self.cinf.SetLabel(str(int(sum([getsize(i) for i in glob("./Images/*.*")]) / 1024 / 10.24) / 100) + " MB, " + str(len(glob("./Images/*.*"))) + " Files")
|
||||||
|
self.SetSize((self.cinf.GetSize().x + 140, DESIGN["Start"][1] + 70))
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Clear History":
|
||||||
|
open(".history", "w").write("")
|
||||||
|
self.hinf.SetLabel(str(len(open(HISTORY, "r").read().split())) + " Entries")
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Save":
|
||||||
|
fr = open(CONFIG, "r")
|
||||||
|
c = fr.read().split()
|
||||||
|
fr.close()
|
||||||
|
fw = open(CONFIG, "w")
|
||||||
|
c[1] = str(int(self.Save.GetValue()))
|
||||||
|
fw.write("\n".join(c))
|
||||||
|
fw.close()
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Hidden":
|
||||||
|
fr = open(CONFIG, "r")
|
||||||
|
c = fr.read().split()
|
||||||
|
fr.close()
|
||||||
|
fw = open(CONFIG, "w")
|
||||||
|
c[2] = str(int(self.Hd.GetValue()))
|
||||||
|
fw.write("\n".join(c))
|
||||||
|
fw.close()
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Safe":
|
||||||
|
fr = open(CONFIG, "r")
|
||||||
|
c = fr.read().split()
|
||||||
|
fr.close()
|
||||||
|
fw = open(CONFIG, "w")
|
||||||
|
c[3] = str(int(self.Ap.GetValue()))
|
||||||
|
fw.write("\n".join(c))
|
||||||
|
fw.close()
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Start":
|
||||||
|
if int(open(CONFIG, "r").read().split()[2]):
|
||||||
|
Popen(["python3", "wrapper.py"], shell=True, creationflags=CREATE_NEW_CONSOLE)
|
||||||
|
else:
|
||||||
|
Popen(["python3", "wrapper.py"], shell=True, creationflags=DETACHED_PROCESS)
|
||||||
|
|
||||||
|
if ids[e.GetId()] == "Refresh":
|
||||||
|
integrity_check()
|
||||||
|
self.hinf.SetLabel(str(len(open(HISTORY, "r").read().split())) + " Entries")
|
||||||
|
self.cinf.SetLabel(str(int(sum([getsize(i) for i in glob("./Images/*.*")]) / 1024 / 10.24) / 100) + " MB, " + str(len(glob("./Images/*.*"))) + " Files")
|
||||||
|
self.SetSize((self.cinf.GetSize().x + 140, DESIGN["Start"][1] + 70))
|
||||||
|
self.Intl.SetValue(open(CONFIG, "r").read().split()[0])
|
||||||
|
self.Save.SetValue(int(open(CONFIG, "r").read().split()[1]))
|
||||||
|
self.Hd.SetValue(int(open(CONFIG, "r").read().split()[2]))
|
||||||
|
self.Ap.SetValue(int(open(CONFIG, "r").read().split()[3]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
integrity_check()
|
||||||
|
app = wx.App()
|
||||||
|
cu = ChangerUI(None)
|
||||||
|
cu.Show()
|
||||||
|
app.MainLoop()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020 Surferlul
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
15
README.md
15
README.md
@ -1,14 +1,19 @@
|
|||||||
# Wallpaper-Changer
|
# Wallpaper-Changer
|
||||||
Wallpaper Changer for Windows using the r/Wallpaper subreddit
|
Wallpaper Changer for Windows using the r/Wallpaper subreddit
|
||||||
|
|
||||||
YOU DO NOT NEED PYTHON TO RUN THIS PROGRAMM
|
PYTHON 3 AND FOLLOWING MODULES ARE REQUIRED TO RUN THIS PROGRAMM:
|
||||||
|
* praw (pip install praw)
|
||||||
|
* progressbar (pip install progressbar)
|
||||||
|
* imgur_downloader (pip install imgur-downloader)
|
||||||
|
* wx (pip install wxPython)
|
||||||
|
|
||||||
If you own python you can download the non-compiled version from the "python" branch
|
Configuration Script: Changer.py<br/>
|
||||||
|
Main Loop: wrappr.py
|
||||||
|
|
||||||
|
The compiled version that doesnt require python is to be found in the main branch
|
||||||
|
|
||||||
If you want to compile it yourself you can download the code from the "code" branch
|
If you want to compile it yourself you can download the code from the "code" branch
|
||||||
|
|
||||||
If you want a more compact version and don't need a UI you can download the program from the "noui_main" branch
|
|
||||||
|
|
||||||
This app uses the reddit api for Python.\
|
This app uses the reddit api for Python.\
|
||||||
The reddit api has limits.\
|
The reddit api has limits.\
|
||||||
The app already had a configured ".client" file with a throwaway client id and client secret so you don't have to create your own reddit app.\
|
The app already had a configured ".client" file with a throwaway client id and client secret so you don't have to create your own reddit app.\
|
||||||
@ -25,7 +30,7 @@ To do so:
|
|||||||
The "redirect uri" isn't important and can be something like http://localhost.
|
The "redirect uri" isn't important and can be something like http://localhost.
|
||||||
Under the name of the app it should say "personal use script".
|
Under the name of the app it should say "personal use script".
|
||||||
Underneath you should find your client id.
|
Underneath you should find your client id.
|
||||||
Put the client id in the first line of a file titled ".client" in the same directory as "Changer.exe".
|
Put the client id in the first line of a file titled ".client" in the same directory as "Changer.py".
|
||||||
You should find the client secret as "secret".
|
You should find the client secret as "secret".
|
||||||
Put the client secret in the second line of the ".client" file.
|
Put the client secret in the second line of the ".client" file.
|
||||||
You're good to go!
|
You're good to go!
|
||||||
|
BIN
backend.exe
BIN
backend.exe
Binary file not shown.
109
backend.py
Normal file
109
backend.py
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
from ctypes import windll
|
||||||
|
from praw import Reddit
|
||||||
|
from glob import glob
|
||||||
|
from time import sleep
|
||||||
|
from time import time
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
from os import getcwd, remove, system
|
||||||
|
import progressbar
|
||||||
|
import urllib.request
|
||||||
|
from imgur_downloader import ImgurDownloader
|
||||||
|
import _thread
|
||||||
|
from subprocess import Popen, CREATE_NEW_CONSOLE
|
||||||
|
|
||||||
|
CONFIG = ".config"
|
||||||
|
CLIENT = ".client"
|
||||||
|
intrvl = float(open(CONFIG, "r").read().split()[0])
|
||||||
|
imgpath = ""
|
||||||
|
start = time()
|
||||||
|
client = open(CLIENT, "r").read().split()
|
||||||
|
|
||||||
|
class NoImage(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
reddit = Reddit(client_id=client[0],
|
||||||
|
client_secret=client[1],
|
||||||
|
user_agent='Wallpaper changer by u/Surferlul')
|
||||||
|
|
||||||
|
class MyProgressBar():
|
||||||
|
def __init__(self):
|
||||||
|
self.pbar = None
|
||||||
|
|
||||||
|
def __call__(self, block_num, block_size, total_size):
|
||||||
|
if not self.pbar:
|
||||||
|
self.pbar=progressbar.ProgressBar(maxval=total_size)
|
||||||
|
self.pbar.start()
|
||||||
|
|
||||||
|
downloaded = block_num * block_size
|
||||||
|
if downloaded < total_size:
|
||||||
|
self.pbar.update(downloaded)
|
||||||
|
else:
|
||||||
|
self.pbar.finish()
|
||||||
|
|
||||||
|
def del_file(path, Seconds=10):
|
||||||
|
Popen("powershell.exe Sleep(" + str(Seconds) + "); Remove-Item .\\Images\\" + path, shell=True, creationflags=CREATE_NEW_CONSOLE)
|
||||||
|
|
||||||
|
posts = open(".history", "r").read()
|
||||||
|
for i in reddit.subreddit("wallpaper").hot(limit = 1000):
|
||||||
|
if i.url not in posts:
|
||||||
|
submission = i
|
||||||
|
break
|
||||||
|
|
||||||
|
open(".history", "a").write(submission.url + "\n")
|
||||||
|
try:
|
||||||
|
if "imgur" in submission.url:
|
||||||
|
if submission.url.split("/")[-1].split(".")[-1] not in ["jpg", "jpeg", "png"]:
|
||||||
|
print("Downoading", submission.url)
|
||||||
|
else:
|
||||||
|
print("Downoading", submission.url, "as", submission.url.split("/")[-1])
|
||||||
|
ImgurDownloader(
|
||||||
|
submission.url,
|
||||||
|
"./Images/",
|
||||||
|
file_name=submission.url.split("/")[-1]
|
||||||
|
if submission.url.split("/")[-1].split(".")[-1] not in ["jpg", "jpeg", "png"]
|
||||||
|
else submission.url.split("/")[-1].split(".")[0]
|
||||||
|
).save_images()
|
||||||
|
if submission.url.split("/")[-1].split(".")[-1] not in ["jpg", "jpeg", "png"]:
|
||||||
|
windll.user32.SystemParametersInfoW(20, 0, getcwd() + "\\" + glob("./Images/" + submission.url.split("/")[-1] + ".*")[0], 0)
|
||||||
|
if not int(open(CONFIG, "r").read().split()[1]):
|
||||||
|
del_file(glob(submission.url.split("/")[-1] + ".*")[0])
|
||||||
|
else:
|
||||||
|
windll.user32.SystemParametersInfoW(20, 0, getcwd() + "\\Images\\" + submission.url.split("/")[-1] , 0)
|
||||||
|
if not int(open(CONFIG, "r").read().split()[1]):
|
||||||
|
del_file(submission.url.split("/")[-1])
|
||||||
|
else:
|
||||||
|
if submission.url.split("/")[-1].split(".")[-1] not in ["jpg", "jpeg", "png"]:
|
||||||
|
raise NoImage
|
||||||
|
imgpath = "Images\\" + submission.url.split("/")[-1]
|
||||||
|
print("Downoading", submission.url, "as", submission.url.split("\\")[-1])
|
||||||
|
urlretrieve(submission.url, imgpath, MyProgressBar())
|
||||||
|
windll.user32.SystemParametersInfoW(20, 0, getcwd() + "\\" + imgpath, 0)
|
||||||
|
if not int(open(CONFIG, "r").read().split()[1]):
|
||||||
|
del_file(submission.url.split("/")[-1])
|
||||||
|
|
||||||
|
end = time()
|
||||||
|
|
||||||
|
intrvl += start - end
|
||||||
|
if intrvl >= 0:
|
||||||
|
pbar = progressbar.ProgressBar(maxval=intrvl)
|
||||||
|
pbar.start()
|
||||||
|
if intrvl < 10:
|
||||||
|
for i in range(1, int(intrvl * 10) + 1):
|
||||||
|
sleep(intrvl / int(intrvl * 10))
|
||||||
|
try:
|
||||||
|
pbar.update(intrvl / int(intrvl * 10) * i)
|
||||||
|
except:
|
||||||
|
pbar.update(int(intrvl))
|
||||||
|
print("test")
|
||||||
|
else:
|
||||||
|
for i in range(1, 101):
|
||||||
|
sleep(intrvl / 100)
|
||||||
|
pbar.update(intrvl / 100 * i)
|
||||||
|
pbar.finish()
|
||||||
|
elif int(open(CONFIG, "r").read().split()[3]):
|
||||||
|
intrvl -= 2 * (start - end)
|
||||||
|
print("Interval was rounded up to " + str(round(intrvl * 100) / 100) + "s because the download needed longer than the interval.")
|
||||||
|
except NoImage:
|
||||||
|
print("Error: Url doesn't point to an Image")
|
||||||
|
except Exception as E:
|
||||||
|
print("Error: " + type(E).__name__)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user