4 ms·
Show HN: Himawari-8 (Whole Earth Geostationary Weather Satellite) Wallpaper Bot
- jarmitage 11y agoFirst ever bit of Python - not very tidy, improvement suggestions welcome! The results are cool though as it updates every 10 minutes. Anyone else do/see anything fun with scripting wallpapers?
- detaro 11y agoCool, both your script and the fact that this resolution of data is available ;) What you can do if you process your background automatically anyways is overlaying current information, e.g. a weather forecast. YR.no has nice 24h-graphs that work well for that. Both PIL and ImageMagick support various blend modes to make it look nice.
- jarmitage 11y agoThanks! Yes, I trust that you saw the commented-out link in the script to the hi-res (5.5k x 5.5k) version that I decided against using? It's awesome! This more advanced bot posts gifs etc https://twitter.com/himawari8bot https://twitter.com/himawari8bot That's a pretty good idea, thanks. Although, whenever I see desktops as dashboards I'm always torn between their utility versus the aesthetic of a clean image. Food for thought...
- detaro 11y agoSince you asked for code improvement suggestions, a few notes. Just what I could think of right now, some are debatable if they apply for such a small one-off script, but I'd say you should at least have seen them. If you have questions later feel free to shoot me an email (address in my user profile), in case I miss a comment here. * I would get rid of the is_connected function. If you are not connected, downloading the file will fail, and you are not doing terribly expensive functions that you'd want to avoid before. And you still have to deal with download errors, because reaching google doesn't mean the server you pull images from is reachable and working. Add error handling for the main download and you are fine. * Don't put code on module level, but add a "main guard" [0] * Look at string formatting methods, they might make your URL-building nicer [1][2] * The removing of the logo would also work with ImageDraw[3] from PIL, no need for numpy * look into urllib2 (also in the standard library), with urllib2.urlopen you can avoid creating a temporary file on disk (+ it is generally the recommended interface in the stdlib) [4] * look at os.path.join [5] to combine file path components * in the loop in Line 45 you are overwriting the name file, which is the inbuild file datatype. If you tried to use that later in the function it wouldn't work anymore... [0] http://stackoverflow.com/a/19578335 http://stackoverflow.com/a/19578335 [1] https://docs.python.org/2.7/tutorial/inputoutput.html#fancier-output-formatting https://docs.python.org/2.7/tutorial/inputoutput.html#fancie... [2] https://www.python.org/dev/peps/pep-3101/ https://www.python.org/dev/peps/pep-3101/ [3] http://omz-software.com/pythonista/docs/ios/ImageDraw.html http://omz-software.com/pythonista/docs/ios/ImageDraw.html [4] https://docs.python.org/2/library/urllib2.html https://docs.python.org/2/library/urllib2.html [5] https://docs.python.org/2/library/os.path.html#os.path.join https://docs.python.org/2/library/os.path.html#os.path.join There is also a newer PIL fork, having ones code work with that also is IMHO good form (haven't checked if yours does): https://pillow.readthedocs.org/en/3.0.x/ https://pillow.readthedocs.org/en/3.0.x/
- jarmitage 11y agoWow, this is very generous of you, thanks a lot! They all look applicable to me, as I was using this script to try out some Python with a view to doing more complicated things later. I will pick up on these and let you know by email if I have any further queries.
- sjs382 11y agoThis is awesome. Seems that Himiwari-8 is a Japanese weather satellite. Do you know a source that offers the other side of the globe? :)
- jarmitage 11y agoThanks! Unfortunately I think it's the only one of its kind! It's quite strange looking at the other side of the world all the time, especially since it is night time there. I have thought about adding a 12 hour offset to the bot so that I get to see daytime when it's day in UK.