3 ms·
Thanks! 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
by jarmitage 11y ago
Thanks! 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.