Exemplo n.º 1
0
    def get(self, *args):
        class_name = self.get_query_argument("class_name")
        print (class_name)
        width = Img.WIDTH
        uuid_str = gen_uuid_32()
        key = class_name + ":" + str(width)
        try:
            page = int(self.get_query_argument("page"))
        except:
            page = 1

        try:
            res_str = self._redis.hget(key, page)
        except:
            res_str = ""
        if res_str:
            res_b64 = base64.standard_b64encode(res_str)
            encrypt_str = uuid_str[:13] + res_b64 + uuid_str[:22]
            print "from redis", page
            self.set_header("Content-Type", "text/plain")
            self.write(encrypt_str)

        else:
            l = LeanCloudApi(class_name)
            limit_num = Img.LIMIT_NUM

            obj_list = l.get_skip_obj_list(page - 1, limit_num=limit_num)

            result = []
            for i in obj_list:
                img_ID = i.get("ID")
                img_url = i.get("File").url
                img_href = img_url.split("/")[-1].replace(".", "_")
                if "gif" in img_href.lower():
                    img_url = img_url + "?vframe/jpg/offset/1|imageMogr2/thumbnail/%sx/interlace/1" % width
                else:
                    img_url = img_url + "?imageMogr2/thumbnail/%sx/interlace/1" % width

                ori_width = i.get("width")
                ori_height = i.get("height")
                try:
                    height = width * ori_height / ori_width
                    each_res = {"href": img_href, "id": img_ID, "image": img_url, "width": width, "height": height}
                except TypeError:
                    each_res = random.choice(default_res)

                result.append(each_res)

            res = {"total": limit_num, "result": result}
            res_str = json_encode(res)

            try:
                self._redis.hset(key, page, res_str)
            except:
                pass
            res_b64 = base64.standard_b64encode(res_str)
            encrypt_str = uuid_str[:13] + res_b64 + uuid_str[:22]
            self.set_header("Content-Type", "text/plain")
            self.write(encrypt_str)
Exemplo n.º 2
0
 def post(self):
     class_name = self.get_body_argument('class_name')
     img_ID = self.get_body_argument('img_id')
     l = LeanCloudApi(class_name)
     try:
         # l.del_by_ID(int(img_ID))
         l.set_by_ID(int(img_ID))  # set img ID to 0
         d = {'msg': 'success', 'img_id': img_ID}
         self.write(d)
     except:
         import traceback
         traceback.print_exc()
         d = {'msg': 'success', 'img_id': img_ID}
         self.write(d)
Exemplo n.º 3
0
 def post(self):
     class_name = self.get_body_argument('class_name')
     img_ID = self.get_body_argument('img_id')
     l = LeanCloudApi(class_name)
     try:
         # l.del_by_ID(int(img_ID))
         l.set_by_ID(int(img_ID))    # set img ID to 0
         d = {'msg': 'success', 'img_id': img_ID}
         self.write(d)
     except:
         import traceback
         traceback.print_exc()
         d = {'msg': 'success', 'img_id': img_ID}
         self.write(d)
Exemplo n.º 4
0
def test():
    l = LeanCloudApi("CatOverload")
    print(l.exist_file('http://40.media.tumblr.com/90793aa5507e1b28b89ee033bb7ca6f1/tumblr_nvqn3kD1fl1up2ssxo1_250.png'))
Exemplo n.º 5
0
def test():
    l = LeanCloudApi("CatOverload")
    print(
        l.exist_file(
            'http://40.media.tumblr.com/90793aa5507e1b28b89ee033bb7ca6f1/tumblr_nvqn3kD1fl1up2ssxo1_250.png'
        ))