예제 #1
0
파일: 1.py 프로젝트: Drizztx/giter
    def post(self):
        arguments = self.request.arguments
        args = dict(arguments)
        if args['action'] == ['random']:
            P = photo_object(CHOICE_COUNT)
            result = P.get_photos(refresh=PKL_REFRESH)
            self.write(result)

        if args['action'] == ['add_love']:
            DB_object = db_object()
            url = args['url'][0].strip()
            path = args['path'][0].strip()

            if DB_object.db_insert(url=url, path=path, is_love=1) != None:
                self.write('ok')
            else:
                self.write('fail')

        if args['action'] == ['delete_love']:
            DB_object = db_object()
            url = args['url'][0].strip()
            path = args['path'][0].strip()
            if DB_object.db_delete(url=url, path=path, is_love=1) != None:
                self.write('ok')
            else:
                self.write('fail')
예제 #2
0
파일: photo.py 프로젝트: Drizztx/giter
    def get_photos(self, refresh = False):
        if refresh:
            self.get_resource()
        with open(PKLFILE,'rb') as f:
            photos = pickle.load(f)

        photo_url, photo_path, photo_number_all  = {},{}, len(photos)

        while len(photo_url) < self.count and len(photo_url.values()) != photo_number_all:
            photo_choice = random.choice(photos)
            if not photo_choice in photo_path.values():
                # key is css id
                key = IMAGE_ID + str(len(photo_url) + 1)
                value2url = photo_choice.replace(RESOURCE,WEBURL).replace('\\','/')
                value2path = photo_choice
                photo_url.update({key:value2url})
                photo_path.update({key:value2path})

        # return prepare
        json_url = json.dumps(photo_url)
        json_path = json.dumps(photo_path)
        DB_object = db_object()
        love_confirm = DB_object.love_confirm(photo_path)
        json_confirm = json.dumps(love_confirm)

        return_content = json.dumps({'url':json_url,'ab_path':json_path,'confirm':json_confirm})

        return return_content
예제 #3
0
파일: 1.py 프로젝트: Drizztx/giter
    def get(self):
        DB_object = db_object()
        love_imgs = DB_object.get_all_like()

        print love_imgs
        self.render('templates/love.html',love_imgs=love_imgs)