예제 #1
0
 def get_hbc_img(self):
     """获取违章黄标车路标图片"""
     url = 'http://%s:%s/wzimg/%s' % (self.hbc_ini['host'],
                                      self.hbc_ini['port'], self.kkdd)
     headers = {'content-type': 'application/json'}
     try:
         r = requests.get(url, headers=headers)
         if r.status_code == 200:
             base_path = u'%s\%s' % (self.wz_img_path, self.kkdd)
             helper.makedirs(base_path)
             for i in json.loads(r.text)['items']:
                 filename = u'%s\%s_%s.jpg' % (base_path, i['kkdd_id'],
                                               i['fxbh_code'])
                 # 如果图片不存在则抓图
                 if not os.path.exists(filename):
                     helper.get_url_img(i['img_url'], filename)
                 self.hbc_img_dict[(i['kkdd_id'],
                                    i['fxbh_code'])] = filename
         else:
             self.hbc_status = False
             raise Exception('url: %s, status: %s, %s' %
                             (url, r.status_code, r.text))
     except Exception as e:
         self.hbc_status = False
         raise
예제 #2
0
 def get_hbc_img(self):
     """获取违章黄标车路标图片"""
     url = 'http://%s:%s/wzimg/%s' % (
         self.hbc_ini['host'], self.hbc_ini['port'], self.kkdd)
     headers = {
         'content-type': 'application/json'
     }
     try:
         r = requests.get(url, headers=headers)
         if r.status_code == 200:
             base_path = u'%s\%s' % (self.wz_img_path, self.kkdd)
             helper.makedirs(base_path)
             for i in json.loads(r.text)['items']:
                 filename = u'%s\%s_%s.jpg' % (base_path, i['kkdd_id'], i['fxbh_code'])
                 # 如果图片不存在则抓图
                 if not os.path.exists(filename):
                     helper.get_url_img(i['img_url'], filename)
                 self.hbc_img_dict[(i['kkdd_id'], i['fxbh_code'])] = filename
         else:
             self.hbc_status = False
             raise Exception('url: %s, status: %s, %s'
                             % (url, r.status_code, r.text))
     except Exception as e:
         self.hbc_status = False
         raise
예제 #3
0
    def fetch_imgs(self, url_list):
        """requests长连接抓取图像"""
	s = requests.Session()
	count = 1
	for url in url_list:
	    helper.get_url_img(url, os.path.join(self.path,'%s.jpg' % count), s)
	    count += 1
예제 #4
0
 def get_img_by_url(self,url,path,name):
     try:
         imgpath = u'%s/%s.jpg' % (path, name)
         helper.get_url_img(url, imgpath)
     except IOError,e:
         print e
         if e[0]== 2 or e[0]==22:
             name = name.replace('*','_').replace('?','_').replace('|','_').replace('<','_').replace('>','_').replace('/','_').replace('\\','_')
             self.makedirs(path)
             imgpath = u'%s/%s.jpg' % (path, name)
             #urllib.urlretrieve(url,local)
             helper.get_url_img(url, imgpath)
         else:
             imgpath = ''
             raise
예제 #5
0
    def post(self):
        parser = reqparse.RequestParser()

        parser.add_argument('imgurl', type=unicode, required=True,
                            help='A jpg url is require', location='json')
        parser.add_argument('coord', type=list, required=True,
                            help='A coordinates array is require',
                            location='json')
        args = parser.parse_args()

        # 回调用的消息队列
        que = Queue.Queue()

        if app.config['RECGQUE'].qsize() > app.config['MAXSIZE']:
            return {'message': 'Server Is Busy'}, 449

        imgname = '%32x' % random.getrandbits(128)
        imgpath = os.path.join(app.config['IMG_PATH'], '%s.jpg' % imgname)
        try:
            helper.get_url_img(request.json['imgurl'], imgpath)
        except Exception as e:
            logger.error('Error url: %s' % request.json['imgurl'])
            return {'message': 'URL Error'}, 400

        app.config['RECGQUE'].put((10, request.json, que, imgpath))

        try:
            recginfo = que.get(timeout=15)

            os.remove(imgpath)
        except Queue.Empty:
            return {'message': 'Timeout'}, 408
        except Exception as e:
            logger.error(e)
        else:
            return {
                'imgurl': request.json['imgurl'],
                'coord': request.json['coord'],
                'recginfo': recginfo
            }, 201