r/learnpython • • Jan 09 '20

I wrote an application that sets your background to NASA's picture of the day!

After some research I figured out that someone already came up with this idea (Great minds think alike!), but he took slightly different approach to this, and his is more advanced I guess. I just wanted to make something for fun, so don't expect this to be even slightly as good as his. Even if I tried it wouldn't be half as good. You can find his attempt at this here.

---------------------------------------------------------------------------------------------

Anyway mine is windows only, and you can find the code here.

Any adviced would be appreciated.

Thanks in advance!

422 Upvotes

54 comments sorted by

131

u/El_Derogator Jan 10 '20

I work at NASA as a software engineer and I’m going to use this to set my work backgrounds.

49

u/glof2 Jan 10 '20 edited Aug 21 '20

Wow, thanks.

95

u/synthphreak Jan 10 '20

If you work at NASA, just avoid the “autolaunch” folder altogether.

0

u/[deleted] Jan 10 '20

[deleted]

1

u/synthphreak Jan 10 '20

My first! I’m forever in your debt.

62

u/El_Derogator Jan 10 '20

Python is my main language so I may tweak it a bit. When I implement it maybe I’ll send you a DM from the Kennedy space center. Keep coding and never lose the passion. Good job and good luck. 👍🏽

24

u/420BJsGamble Jan 10 '20

😭coders are so friendly and nice

6

u/mutwiri_2 Jan 10 '20

So true. I swear there is no other profession where people build and encourage each other like programmers.

10

u/mr-bope Jan 10 '20

Unless you’re on stackoverflow...

Might write this in Python for Linux PCs.

6

u/mutwiri_2 Jan 10 '20

yea stackoverflow has some bad apples but I think it's just because they are older in the game and do not take kindly to newbies who ask some ignorant questions sometimes...

I am a linux user, I would definitely love to see a linux version

2

u/420BJsGamble Jan 10 '20

Seriously. Like every profession / even life it seems like everything is a constant completion...

From the moment I started coding people have been nothing but kind. Not to mention the amount of people that lend their TIME to show you how things work. It’s incredible. Love you all

2

u/mutwiri_2 Jan 10 '20

It is incredible, honestly, and it just builds in you that desire to help someone else and what an incredible community we build.

13

u/mtlFP Jan 10 '20

I would hope the security systems at NASA would block a python program from the wild to be on their network (cybersecurity guy here)

24

u/El_Derogator Jan 10 '20 edited Jan 10 '20

Oh absolutely. My closest co-workers are cyber security. Granted, I do work more in application development for the center. This is also the reason I said I would tweak the code myself ensuring there isn’t a security risk. This is code I could have written myself, but encourage the efforts of OP. Rest assured no risk would be allowed.

4

u/panoptictechguy Jan 10 '20

This is really cool, thanks for sharing. Hope you don't mind but I transposed this for Linux (Mint/Ubuntu), the file is here. I also took out the loop, I'll just cron it on Linux :)

Ultimately I'd want to have it OS agnostic and detect the OS (with sys.platform for example) and adjust accordingly

3

u/glof2 Jan 10 '20

That's not a problem, I originally wanted to do that, but I could not figure out how to set a file as wallpaper on Linux (Google didn't give me answers). I was going to use sys.name() if that helps you. Anyway have fun coding!

3

u/panoptictechguy Jan 10 '20

On Ubuntu/Mint you use the "gsettings" command to set it from the command line so I just use the OS module to issue the command line command. There's probably a better way but this was easy and worked.

3

u/glof2 Jan 10 '20

Okay, thanks for telling me, I never used Ubuntu terminal in my life lol, again have fun coding, and make sure to message me once you finish it, I'll be glad to check it out!

4

u/LightUmbra Jan 10 '20

One note. time.sleep() can have problems over long periods of time and normally shouldn't be used for this type of scheduling (I can't really explain the reasons, but there are probably some good articles on it). The best way to do it would be to take advantage of your os's scheduler, Task Scheduler for windows and cron for Linux. You can set it to run pythonw.exe wallpaper_thing.py once every hour and it will run better.

2

u/glof2 Jan 10 '20

Will do, thank you!

5

u/Ertersy Jan 10 '20

hey, this is awesome and i tried to get it to work but it isn't changing the background...

I put it in the appdata file and it's a .py file but doesn't change anything. Anything I'm missing? I would really love it if i could get this to work, thanks!

0

u/[deleted] Jan 10 '20

[deleted]

4

u/Ertersy Jan 10 '20

I've set python to default launch but even when i manually launch it, it just doesn't change the background... Thanks for the speedy reply

7

u/glof2 Jan 10 '20

Okay, did you unzip it?

3

u/Ertersy Jan 10 '20

perhaps not... how would i do that?

4

u/glof2 Jan 10 '20

Nevermind I think I know what happened, could you open your command prompt, and drag the .py file over to it? It should automatically type the .py file path for you, from there just click enter and tell me what happens

3

u/Ertersy Jan 10 '20

Traceback (most recent call last):

File "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\nasa.py", line 2, in <module>

from bs4 import BeautifulSoup

ModuleNotFoundError: No module named 'bs4'

6

u/glof2 Jan 10 '20

Yup, just as i thought, open your command prompt as an administrator and type in "pip install BeautifulSoup4" and then "pip install requests" you should be able to launch the program now!

3

u/Ertersy Jan 10 '20

Thank you so much! Got it!

This is awesome! You have been so helpful, thanks for being a legend!

5

u/glof2 Jan 10 '20

No problem at all! You can add me on Discord: MayooXD#2527 if you ever need help! Also somewhere in this post I posted some learning resource links, you can check them out. Good luck in learning the language, and never give up!

5

u/-stay- Jan 10 '20

Get into linux m8 🐧🐧🐧🐧🐧🐧👌 good job btw

2

u/TwoThirteen Jan 10 '20

1

u/glof2 Jan 10 '20

From this site: https://apod.nasa.gov/ to be more specific, it redirects you to the newest picture of the day, so the program works no matter what day it is!

2

u/killerinstinct101 PhoenixFlame101 Jan 10 '20

That's pretty cool! I do something similar but with the top images from r/wallpapers.

Edit: I suggest you get rid of time.sleep() and use windows task scheduler (or something similar).

1

u/glof2 Jan 10 '20

Will do, thank you! Have fun coding!

2

u/skiutoss Jan 10 '20

Nice work!

1

u/glof2 Jan 10 '20

Thank you!

2

u/buleria Jan 10 '20

filepath = getcwd() + r"\\" + filename

You shouldn't do that, even though you target windows only. Check https://docs.python.org/library/os.path.html#os.path.join for a proper way.

1

u/glof2 Jan 10 '20

Thanks!

2

u/pakayahey Jan 10 '20

How to install this ?

2

u/glof2 Jan 10 '20

Go to the github gists link i provided (here), and in the top right corner you have "download as zip". Click that and after it downloads, unzip it. Write back if you have any more issues!

18

u/[deleted] Jan 09 '20

That’s such a cool idea. You got me feeling inspired to come up with an idea as good as this one!

10

u/gtmattz Jan 09 '20

Funny, when I was teaching myself python years ago this was one of the things I came up with to learn on, except it was pictures of the sun from the SOHO site.

6

u/RicealiciousRice Jan 09 '20

Woah you can do this?!?! Makes me really want to learn to program!!

0

u/[deleted] Jan 09 '20

[deleted]

11

u/RicealiciousRice Jan 10 '20

Lol I’m sorry if I come off sarcastic. I genuinely think this is cool. And thanks!

3

u/[deleted] Jan 09 '20

That's dope!

0

u/[deleted] Jan 09 '20

[deleted]

2

u/[deleted] Jan 09 '20

Trying to get my skills up to snuff with yours hahaha

0

u/[deleted] Jan 09 '20

[deleted]

4

u/[deleted] Jan 09 '20

Thanks a ton for typing this up

I'm in Jose Portillas Udemy class on DA right now but will be sure to check out automate the boring stuff!

1

u/[deleted] Jan 10 '20

This is cool and all that, but display fusion already does this. Not saying your effort and work wasn't necessary, or warrants praise.

I'm glad you did something cool, and I hope you learned something along the way.

0

u/[deleted] Jan 10 '20

[deleted]

1

u/glof2 Jan 10 '20

You definitely should, it's fun. So good luck and have fun coding, I'm glad this could inspire you lol, thanks

0

u/[deleted] Jan 10 '20

[deleted]

1

u/glof2 Jan 10 '20

"user32.dll is a module that contains Windows API functions related the Windows user interface (Window handling, basic UI functions, and so forth).", " ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. "

3

u/[deleted] Jan 10 '20

[removed] — view removed comment

1

u/glof2 Jan 10 '20

No problem! I'm glad you learnt something!