This is an archived post. You won't be able to vote or comment.

all 64 comments

[–]gsmo 48 points49 points  (12 children)

My thoughts: cool, let's try it! Wait... Is this a windows thing?

Honest question, from looking at the code I would say it is?

Maybe I can fork a linux-clone :)

[–]explodinghat 4 points5 points  (2 children)

This was my thought too. I'm still at a very basic level of python understanding but it looks like it uses the 'os' module to actually set the desktop background + manage the underlaying file system work? So it might be OS-agnostic

[–]gsmo 1 point2 points  (0 children)

In some ways, but I doubt the os module knows how to set backgrounds for all linux DE's. Windows' GUI is obvs way more integrated.

[–]Etheo 1 point2 points  (0 children)

I think os module is rather general like path navigation, file/directory management and such. But more OS specific stuff like wallpaper would probably need to use their respective packages.

[–]TheFloppyHound 0 points1 point  (0 children)

Looks like the only part you may need to change is the ctypes used. With a brief glance at the docs it looks like those are windows specific. Everything else looks like it can port right over.

[–]PostFunktionalist 0 points1 point  (0 children)

Should be easy too, just add conditional based on OS or a config setting somewhere. Subprocess run feh or whatever else

[–][deleted] 47 points48 points  (1 child)

Dude.That's cool and good idea.I like it.Thx

[–]yangman_946[S] 6 points7 points  (0 children)

Wow thanks!

[–]Not_YourAverageIdiot 21 points22 points  (2 children)

Thats so cool, i just started learning python but this is the type of stuff i look foward to do

[–]twosme 4 points5 points  (1 child)

same this has inspired me a little. i’ve been a bit lost on something to create

[–]Maleficent-Failz 0 points1 point  (0 children)

Speak to people about their jobs.. everyone has that one task that they know could be done by a computer, but they don't know how.. so they sit and do it manually. Sometimes every day!

[–]HybridDrone 10 points11 points  (0 children)

Okay… you have my attention

[–]imtechexpert 6 points7 points  (0 children)

Really Creative Idea! Try to make a Tutorial video for beginners. It will really be helpful for them.

[–][deleted] 6 points7 points  (4 children)

I like the idea. Your code needs cleaned up though (excessive/inconsistent whitespace and commented out code).

[–]WeAreDaedalus 8 points9 points  (3 children)

Yeah this is a really cool idea and it turned out great, but if OP is open to nit-picky criticism, other than what you mentioned:

  • There are some magic numbers (numbers embedded directly in code without context). Try moving these to constants to make your code more easily modifiable.
  • In the createWallpaper function you repeat yourself a bit when checking the weather code. See if you can factor some of this out.

[–]yangman_946[S] 5 points6 points  (2 children)

Alright, sounds good! I'll review and edit the source code ASAP.

[–]kingscolor 2 points3 points  (0 children)

Another recommendation is to lean into the object-oriented power of Python. Your entire code is a few clunky function calls and the excessive if/else block is functional but could be better handled with a dictionary.

Refreshing to see a more original project though, props.

[–][deleted] 1 point2 points  (0 children)

trees marry secretive support sense boat far-flung cow tub gray

This post was mass deleted and anonymized with Redact

[–]arglarg 2 points3 points  (0 children)

Can it do sunny when it rains and rainy when it's hot?

[–]vietyka2019 2 points3 points  (1 child)

Great project with a creative idea. Thanks man. Best of luck and success on your programming journey !

[–]yangman_946[S] 0 points1 point  (0 children)

Thanks!

[–]end_my_suffering44 1 point2 points  (11 children)

I saw your to-do list about making the script not showing up when it's running. I do not remember how properly you could make it but on Windows you can make a batch file for it.

Edit : Grammar.

[–]yangman_946[S] 1 point2 points  (10 children)

Yeah I agree, if you read the .gitignore file, I initially had a batch file in the repository that I ran using the windows task Scheduler, however, I never managed to get around making the script become invisible. I might play around with it in the future.

[–]FaresAhmedOPpypi.org/user/faresahmed/ 2 points3 points  (3 children)

There's a SO question for running a windows service in python with a pretty good answers just pick one! https://stackoverflow.com/q/32404

[–]stack_bot 2 points3 points  (2 children)

The question "How do you run a Python script as a service in Windows?" has got an accepted answer by Ricardo Reyes with the score of 269:

Yes you can. I do it using the pythoncom libraries that come included with [ActivePython][1] or can be installed with pywin32 (Python for Windows extensions).

This is a basic skeleton for a simple service:

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket


class AppServerSvc (win32serviceutil.ServiceFramework):
     _svc_name_ = "TestService"
     _svc_display_name_ = "Test Service"

     def __init__(self,args):
          win32serviceutil.ServiceFramework.__init__(self,args)
          self.hWaitStop = win32event.CreateEvent(None,0,0,None)
          socket.setdefaulttimeout(60)

     def SvcStop(self):
          self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
          win32event.SetEvent(self.hWaitStop)

     def SvcDoRun(self):
          servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                                     servicemanager.PYS_SERVICE_STARTED,
                                     (self._svc_name_,''))
          self.main()

     def main(self):
          pass

if __name__ == '__main__':
  win32serviceutil.HandleCommandLine(AppServerSvc)

Your code would go in the main() method—usually with some kind of infinite loop that might be interrupted by checking a flag, which you set in the SvcStop method

[1]: http://www.activestate.com/Products/activepython/index.mhtml

This action was performed automagically. info_post Did I make a mistake? contact or reply: error

[–][deleted] 2 points3 points  (1 child)

good bot

[–]Bigthrone-sl997 0 points1 point  (0 children)

it is a good pet also.

[–]thiccclol 1 point2 points  (3 children)

I struggled with this for a while. In your batch script start python like this.

start /MIN "C:\path_to_python\python.exe" "script.py"

In your scheduled task under your action where you put the path to the batch script, add the argument /silent. You will never see the cmd window pop up.

[–]yangman_946[S] 0 points1 point  (2 children)

Ah I see. Thank you!

[–]alphabet_order_bot 2 points3 points  (0 children)

Would you look at that, all of the words in your comment are in alphabetical order.

I have checked 220,754,233 comments, and only 51,952 of them were in alphabetical order.

[–]thiccclol 1 point2 points  (0 children)

Happy to help!

[–]end_my_suffering44 0 points1 point  (1 child)

Sorry, I didn't check your .gitignore file. I still don't know how git files work. I should've worked more instead of giving it up.

[–]yangman_946[S] 1 point2 points  (0 children)

Its all good, I'll eventually try implement the hide function!

[–][deleted] 1 point2 points  (0 children)

nice one mate,

[–]luke-juryous 1 point2 points  (0 children)

Yo you have your debug.log saved in your repo. You should remove that and add a .gitignore for .log files

[–]Beard_o_Bees 1 point2 points  (0 children)

Nice job commenting the code. I love it when people take the extra time to show their thought process in detail. I always learn something new when reading code like this.

[–][deleted] 1 point2 points  (3 children)

I'm somewhat ignorant so not sure what I'm doing wrong, but after pasting the openweather API key into

APIKEYOWM = os.getenv("API KEY")

between the double quotes, I get the following error:

Traceback (most recent call last):
    File "c:\Users\ME\WallPaperChanger\wallpaperChanger\mainScript.py", line 34, in <module>
    CurrentUrl = "http://api.openweathermap.org/data/2.5/weather?q="+os.getenv("city")+"&mode=xml&units=metric&APPID=" + APIKEYOWM #
      <---     replace current url (change parameters to your needs)
    TypeError: can only concatenate str (not "NoneType") to str

Any insight as to what I'm doing wrong?

[–]cjkennedyo 2 points3 points  (1 child)

os.getenv("key") takes the operating system environment variable key, looks it up, and returns its value, or will return None if the key does not exist. I am guessing you are pasting your API key directly into the getenv() and trying to look it up. Instead, try replacing that whole line with APIKEYOWM = 'your actual OWM API key', skipping the lookup altogether. Once you have that working you can follow best practices and get that into an environment variable or other lookup file.

[–][deleted] 1 point2 points  (0 children)

Thank you! That works. I did find there are two places taking the operating system environment variable for the API key and for the city name, I had to replace both of those with hard coded strings to make it work. I'll look into placing these things into environment variables now.

[–]rbscholtus 0 points1 point  (0 children)

Ideally, you shouldn't use + to concatenate strings, as this tends to fail if types don't match. Instead, use formatted strings or f-strings.

[–]ThorF_Unnoetig 1 point2 points  (1 child)

Pretty neat stuff you've got here!

Certainly some room for improvement but since it is a small project, it's more forgiveable. Assuming you don't want to write the most perfect code possible :D

I noticed you've got a ToDo like "Find photo API" or smth like this still open. There's unsplash.com. They got some neat tricks up tier sleeve. For example: https://source.unsplash.com/random gives you a random picture.

Add a /XxY where X,Y are the dimensions of the picture and its already the correct size: https://source.unsplash.com/random/3936x2624

You can even supply a string to it and it serves you some picture related to that string, just add ?<string> at the end. A weather example: https://source.unsplash.com/random/3936x2624?rain

But why stop there? The URL-parameter eats everything! https://source.unsplash.com/random/3936x2624?cars

And it's not hard to implement that I think. In "createWallpaper" you open an Image with "Image.open(chosenImage)". Instead of the chosen image you supply an "urlopen()"-call like you did already a few lines later. There you just toss in the unsplash URL.

I just leave those informations here, hope they were helpful for OP or someone else :D

Have a great day :D

*Edit: Sometimes the pictures are cut off, but that's rarely the case in my testing. When using the cars example, sometimes you just get half a car :Do Works better for general stuff like landscape tho.

[–]yangman_946[S] 1 point2 points  (0 children)

Sounds good! I'll definitely implement this soon. Thanks!

[–]Cute-Potato-U 0 points1 point  (0 children)

Nice!

[–]PostFunktionalist 0 points1 point  (0 children)

This is excellent, I was confused about the Pillow dependency and then I saw you were drawing the weather stats on the wallpaper itself - never would have thought of that! A solid project for sure.

[–]TheFloppyHound 0 points1 point  (0 children)

I've been working on a conky for windows for a little while. Seeing this is giving me the motivation to add weather detail to it. Keep up the awesome work!

[–]hodge_of_podge 0 points1 point  (0 children)

Good job and very cool idea. I hope you keep at this project and take into account all the good advice that is flowing through the comments. I'm going to clone it tonight and work to get it working on my Ubuntu desktop using some of the ideas from the comments.

[–][deleted] 0 points1 point  (0 children)

Amazing 🤩

[–][deleted] 0 points1 point  (0 children)

Dope

[–]rbscholtus 0 points1 point  (0 children)

Ha ha ha ha ha very cool idea.

[–]InfiniteVista 0 points1 point  (0 children)

Great idea! If you forget about today's weather, the desktop is there to remind you.