# your code goes hereimport sys
import urllib.request
import os.path


def dload(url,a):
    req=urllib.request.Request(url)
    try:
        img=urllib.request.urlopen(req)
        localfile=open(os.path.basename(a),"wb")
        localfile.write(img.read())
        img.close()
        localfile.close()
    except urllib.error.URLError as e:
        print(a)
        print(e.reason)

f=open("urls.txt","r")
a=0
for line in f:
   a=a+1
   string=str(a)
   fname="pic"+string.zfill(3)+".jpg"
   dname=os.getcwd()
   fpath=os.path.join(dname,fname)

   print("start "+fpath)
   print(os.path.isfile(a))
   if os.path.isfile(a)!= True :
       dload(line,fpath)
       print("end "+fpath)

