Created
August 13, 2014 17:03
-
-
Save ShambhalaLogan/96d2753d00cd6e6a5018 to your computer and use it in GitHub Desktop.
DL-IMG.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,console | |
from urllib import urlopen | |
from time import sleep | |
from PIL import Image | |
console.clear() | |
folderPath = 'ImageFiles/Imported/' | |
imgPath='Insults' | |
urlPath='http://i.imgur.com/q4UXODX.png' | |
print '\nDownloading...' | |
def ldImg(imgPath,folderPath='Images',urlPath='Null'): | |
try: | |
if folderPath: folderPath+="/" | |
if not os.path.exists(folderPath[:-1]): os.mkdir(folderPath[:-1]) | |
url = urlopen(urlPath) | |
with open(folderPath+imgPath+'.png', "wb") as output: | |
output.write(url.read()) | |
return os.getcwd()+'/'+folderPath+imgPath | |
except: | |
console.set_color(1,0,0) | |
print '\nERROR: Download failed.' | |
def testPix(ik): | |
print ik | |
try: | |
lddImg = ldImg(imgPath,folderPath,urlPath) | |
Image.open(lddImg+'.png').show() | |
print folderPath+imgPath+".png has been downloaded.\n" | |
testPix(open(lddImg+'.png')) | |
except: | |
print "\nERROR: Download failed." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment