Beispiel #1
0
 def _image_doc(self, folder, rel_path):
     full_path = os.path.join(folder, rel_path)
     args = ['--metadata']
     if 'time_zone' in self._source:
         args.extend(['--timezone', self._source['time_zone']])
     args.extend(['--thumbnail', '64', '--thumbnail', '512'])
     doc, logs = image.get(full_path, *args)
     
     for log in logs:
         log['path'] = "%s/%s" % (self._source['_id'], rel_path)
         self._log.append(log)
     
     if not doc:
         return
     
     if 'original_info' in doc:
         del doc['original_info']
     doc['_id'] = "img-%s" % uuid.uuid4().hex
     doc[IMAGE_TYPE] = True
     
     idents = doc.setdefault('identifiers', {})
     idents['path'] = {'source':couch.make_ref(self._source), 'name':rel_path}
     with open(full_path, 'rb') as f:
         md5 = hashlib.md5()
         sha1 = hashlib.sha1()
         while True:
             buff = f.read(524288)
             if not buff:
                 break
             md5.update(buff)
             sha1.update(buff)
     idents['md5'] = md5.hexdigest()
     idents['sha1'] = sha1.hexdigest()
     
     return doc
Beispiel #2
0
 def __init__(self):
     import image
     self.colors = image.random_color_scheme("personal")
     print self.colors
     self.sprites = [image.get("cha_f_mechanic.png", self.colors, (64*(i%4), 64*(i//4), 64, 64)) for i in range(8)]
     self.orientation = 0
     self.map = None
     self.coords = (0,0)
Beispiel #3
0
    def save_histogram_to_frontend(self, histogramArr):
        graylevel = self.mainImageObject.getGrayLevel()
        arrTemp = np.zeros((3, graylevel), dtype='uint8')
        for i in range(3):
            for j in range(graylevel):
                arrTemp[i][j] = image.get(histogramArr, i, j)

        return arrTemp
Beispiel #4
0
 def _get_jpeg(self, image_path, size, metadata=False):
     name = 'export' if metadata else 'thumbnail'
     doc, _ = image.get(image_path, '--%s' % name, size)
     if doc:
         img = doc.get('_attachments', {}).get('%s/%s.jpg' % (name, size))
         if img:
             headers = {'Content-Type':img['content_type']}
             return {'code':200, 'headers':headers, 'base64':img['data']}
     return {'code':500, 'json':{'error':True, 'reason':"Failed to get image"}}
Beispiel #5
0
    def save_array_to_frontend(self, imgObject):
        arrTemp = np.zeros((imgObject.getHeight(), imgObject.getWidth(), 3),
                           dtype='uint8')
        for i in range(imgObject.getHeight()):
            for j in range(imgObject.getWidth()):
                for k in range(3):
                    arrTemp[i][j][k] = image.get(imgObject.getPixels(), i, j,
                                                 k)

        return arrTemp
Beispiel #6
0
 def __init__(self, map_to_draw):
     self.view_x = 0
     self.view_y = 0
     self.map_to_draw = map_to_draw
     self.mouse_cursor = image.get("target64.png", None, (0,0,64,64))
Beispiel #7
0
 def sprite(self):
     if self._sprite is None:
         self._sprite = image.get(*self.sdl_image_spec)
     return self._sprite
Beispiel #8
0
def main(pages):
    global _IMAGE_CNT, _VIDEO_CNT

    for i in range(pages):
        url = _GRAP_URL + '&page=' + str(i)
        html_doc = urllib.urlopen(url).read()
        if html_doc:
            soup = BeautifulSoup(html_doc)
            try:
                # ============================================================
                # 采集视频
                # ============================================================
                target_divs = soup.find_all('article', {'class': 'post-video'})
                if target_divs and len(target_divs):
                    for td in target_divs:
                        # 资源标题
                        title = td.find('h2')['title']
                        video_src = td.find('embed')['src'].strip()
                        # FIXME url
                        video_id = _get_video_id('http://player.56.com/renrenshare_(.*).swf/1030_.*.swf', video_src)
                        if not video_id:
                            continue
                        # 获取视频信息
                        video_info = _get_video_info(video_id)
                        if video_info.get('info', None):
                            video_img = video_info['info']['bimg']
                            # 不抓取重复资源
                            if db.exists(video_src):
                                continue

                            resource_info = _deal_resource(video_img)
                            resource_info['url'] = video_src
                            resource = db.SpideResource(title, 'video', json.dumps(resource_info), video_src)
                            db.save(resource)
                            print '成功爬取视频资源!'
                            _VIDEO_CNT = _VIDEO_CNT + 1
                        else:
                            print 'Fail to get video_info by: %s %s' % (video_src, video_id)

            except Exception, err:
                print '[VideoError] ' + str(err)

            try:
                # ============================================================
                # 采集图片
                # ============================================================
                target_divs = soup.find_all('article', {'class': ['post-photo', 'post-article']})
                if target_divs and len(target_divs):
                    for td in target_divs:
                        post_content = td.find('div', {'class': 'post-content'})
                        # 资源标题
                        title = post_content.find('h2')['title']
                        images = post_content.find_all('img')
                        # 抓取只有一副图片的资源
                        if images and len(images) == 1:
                            image = images[0]
                            if image.get('data-src', None):
                                image_src = image['data-src'].strip()
                            else:
                                image_src = image['src'].strip()
                            # 不抓取重复资源
                            if db.exists(image_src):
                                continue

                            resource_info = _deal_resource(image_src)
                            resource = db.SpideResource(title, 'image', json.dumps(resource_info), image_src)
                            db.save(resource)
                            print '成功爬取图片资源!'
                            _IMAGE_CNT = _IMAGE_CNT + 1

            except Exception, err:
                print '[ImageError] ' + str(err)
Beispiel #9
0
 def sprite(self):
     if self.orien==Door.OR_HORI: x=64
     else: x=0
     y = 0
     if not self.closed: y = 96
     return image.get("door_a.png", None, (x,y,64,96))
Beispiel #10
0
 if cmd == "help":
     print("SmartTrash控制台帮助")
     print("about或version-----显示版本信息")
     print("help-----显示此帮助")
     print("stop或exit-----退出程序")
     print("")
 elif cmd == "stop" or cmd == "exit":
     stop()
 elif cmd == "about" or cmd == "version":
     about()
 elif cmd == "take":
     image.take()
 elif cmd == "imgc":
     image.image_classify(image.image)
 elif cmd == "get":
     image.get()
 elif cmd == 'type':
     image.getType(image.result['result'][0]['keyword'] + '/' +
                   image.result['result'][0]['root'])
 elif cmd == 'run':
     run()
 elif cmd == 'setdist':
     distance.distmin = float(input('input the distmin:'))
 elif cmd == 'setdisttime':
     distance.whiletime = float(input('input the whiletime:'))
 elif cmd == '':
     pass
 else:
     print("未知命令 输入help查看帮助")
 cmd = ""
 # --------------------------------------