r/tinycode • u/f0rkbomb • Jul 13 '12
Random Imgur Downloader (Python)
https://gist.github.com/30881281
u/f0rkbomb Jul 13 '12
the kind folks in /r/python encouraged me to cross-post this here :)
still some room for optimization/tinifying! but in the meantime, enjoy downloading random (and often nsfw) pics
4
u/plux Jul 13 '12 edited Jul 13 '12
I don't get it. This is a lot of code for doing something this simple.
And why the hell are you spawning of threads to do this?
This is bloated code - the opposite of what /r/tinycode is meant for.
EDIT:
Also, it doesn't even seem to work correctly, it just downloads the "404" image for me.
Another general coding advice, don't treat file paths as strings, use the os.path module for gods sake!
4
u/PsychoMario Jul 13 '12 edited Jul 14 '12
while [ 1 = 1 ]; do wget i.imgur.com/$(cat /dev/urandom | tr -cd "[:alnum:]" | head -c 6).jpg; doneEDIT:
for i in *; do mv $i $(md5sum $i | cut -d' ' -f1).jpg;done1
6
u/plux Jul 13 '12 edited Jul 13 '12
I decided to try to shorten this bloated code to keep it in the spirit of /r/tinycode.
I got it down to 12 lines of code without sacrificing readability.
I did a slighty obfuscated version that is 6 lines of code.