Exemplo n.º 1
0
 def __init__(self,query="Rocket",results=50, with_cache=None,rescale=None):
   done=False
   self.rescale=rescale
   if (with_cache):
     try:
        os.stat(with_cache+"/"+query.lower())
        f=file(with_cache+"/"+query+"/reader.pcl","rb")
        self.query=pickle.load(f)
        self.urls=pickle.load(f)
        self.destdir=pickle.load(f)
        self.lq=pickle.load(f)
        done=True
     except: 
        pass
   if not done:
     from pycvf.core import settings
     from yahoo.search.image import ImageSearch
     yahoo_image_search=ImageSearch(settings.YAHOOAPPID)
     yahoo_image_search.query = query
     yahoo_image_search.results = results
     r=yahoo_image_search.get_results()
     self.query=query
     self.urls=[ ]
     for i in range(40):
        try:
           self.urls.append(r.childNodes[0].getElementsByTagName('Result')[i].getElementsByTagName('Url')[0].childNodes[0].nodeValue)
        except:
           pass
     if not (with_cache):
       self.destdir="/tmp/"+yahoo_image_search.query.lower()
     else:
       self.destdir=with_cache+yahoo_image_search.query.lower()
     try:
       os.mkdir(self.destdir)
     except:
       pass
     self.lq=len(self.urls)
     dl=map(lambda i:(self.urls[i],(self.destdir+"/f-"+str(i)+"."+self.urls[i].split(".")[-1]).lower()) ,range(len(self.urls)))
     if (self.lq):
       md=MultiDownloader(dl)
       md.run()
   if (with_cache):
     try:
       os.mkdir(with_cache+"/"+query.lower())
     except:
       pass
     f=file(with_cache+"/"+query+"/reader.pcl","wb")
     pickle.dump(self.query,f,protocol=2)
     pickle.dump(self.urls,f,protocol=2)
     pickle.dump(self.destdir,f,protocol=2)
     pickle.dump(self.lq,f,protocol=2)
     f.close()
Exemplo n.º 2
0
 def __init__(self,query="factory", limit=40,with_cache=None,rescale=(300,400,'T')):
   done=False
   self.rescale=rescale
   if (with_cache):
     try:
        os.stat(with_cache+"/"+query.lower())
        f=file(with_cache+"/"+query+"/reader.pcl","rb")
        self.query=pickle.load(f)
        self.urls=pickle.load(f)
        self.destdir=pickle.load(f)
        self.lq=pickle.load(f)
        done=True
     except: 
        pass
   if not done:    
     self.query=query
     self.urls=ImageNet.urls(query,limit)
     pycvf_debug(10,str(self.urls))
     if not (with_cache):
       self.destdir="/tmp/"+query.lower()
     else:
       self.destdir=with_cache+yahoo_image_search.query.lower()
     try:
       os.mkdir(self.destdir)
     except:
       pass
     self.lq=len(self.urls)
     dl=map(lambda i:(self.urls[i],(self.destdir+"/f-"+str(i)+"."+self.urls[i].split(".")[-1]).lower()) ,range(len(self.urls)))
     if (self.lq):
       md=MultiDownloader(dl)
       md.run()
   if (with_cache):
     try:
       os.mkdir(with_cache+"/"+query.lower())
     except:
       pass
     f=file(with_cache+"/"+query+"/reader.pcl","wb")
     pickle.dump(self.query,f,protocol=2)
     pickle.dump(self.urls,f,protocol=2)
     pickle.dump(self.destdir,f,protocol=2)
     pickle.dump(self.lq,f,protocol=2)
     f.close()