Exemple #1
0
def images(pagenumber):
    """查询"""
    args = request.args
    tag = args.get("tag", None, type=str)
    if tag:
        tag = tag.split(" ")
    pagesize = args.get("pagesize", 10, type=int)
    score = args.get("score", 0, type=int)
    sort = args.get("sort", "score", type=str)
    pageindex = pagenumber - 1
    print('score:%s;tag:%s;pagesize:%s;pageindex:%s;sort: %s' %
          (score, tag, pagesize, pageindex, sort))
    if sort == "random":
        data = Store.FileHistoryRepository().getsradom(score, tag, pagesize)
    else:
        data = Store.FileHistoryRepository().getspage(score, tag, pageindex,
                                                      pagesize, sort)
    return jsonify({
        'items': [{
            'id': item.id,
            'url': item.filepath.replace("\\", "/"),
            'md5': item.md5,
            'score': item.remark1,
            'tags': item.remark2
        } for item in data["list"]],
        'total':
        data["total"]
    })
Exemple #2
0
def imagesbysection(star, end):
    """查询"""
    args = request.args
    tag = args.get("tag", None, type=str)
    if tag:
        tag = tag.split(" ")
    score = args.get("score", 0, type=int)
    sort = args.get("sort", "score", type=str)
    print('score:%s;tag:%s;star:%s;end:%s;sort: %s' %
          (score, tag, star, end, sort))
    if sort == "random":
        sectionlength = end - star
        data = Store.FileHistoryRepository().getsradom(score, tag,
                                                       sectionlength)
    else:
        data = Store.FileHistoryRepository().getsbysection(
            score, tag, star, end, sort)
    return jsonify({
        'items': [{
            'id': item.id,
            'url': item.filepath.replace("\\", "/"),
            'md5': item.md5,
            'score': item.remark1,
            'tags': item.remark2
        } for item in data["list"]],
        'total':
        data["total"]
    })
Exemple #3
0
def image(imageid):
    """查询"""
    data = Store.FileHistoryRepository().getbyid(imageid)
    return jsonify({
        'id': data.id,
        'url': data.filepath.replace("\\", "/"),
        'md5': data.md5,
        'score': data.remark1,
        'tags': data.remark2
    } if data else {})
Exemple #4
0
def detail():
    """设置详情"""
    data = Store.FileHistoryRepository().getspage(pageindex=0)
    total = data["total"]
    progressbar = Tool.ProgressBar(total=total)
    successcount = 0
    pageindex = 0
    while True:
        datapage = Store.FileHistoryRepository().getspage(pageindex=pageindex)
        for item in datapage["list"]:
            # print(item)
            tags = item.remark2.split(" ")
            for tag in tags:
                if tag:
                    Store.TagRepository().addorupdate(tag)
            successcount = successcount + 1
            progressbar.move("成功%s;" % (successcount))
        if len(datapage["list"]) == 0:
            break
        pageindex = pageindex + 1
    print("共需处理%s;成功%s;" % (total, successcount))
Exemple #5
0
def detail():
    """设置详情"""
    data = Store.FileHistoryRepository().getsremarknull(0, 1)
    total = data["total"]
    progressbar = Tool.ProgressBar(total=total)
    pagesize = 10
    successcount = 0
    while True:
        pageindex = 0
        sucesscountcurrent = 0  ##当前循环成功数量
        while True:
            datapage = Store.FileHistoryRepository().getsremarknull(
                pageindex, pagesize)
            for item in datapage["list"]:
                if Store.FileHistoryRepository().setremarkbymd5(item.md5):
                    successcount = successcount + 1
                    sucesscountcurrent = sucesscountcurrent + 1
                    progressbar.move("成功%s;" % (successcount))
            if len(datapage["list"]) == 0:
                break
            pageindex = pageindex + 1
        if sucesscountcurrent == 0 or successcount >= total:
            break
    print("共需处理%s;成功%s;" % (total, successcount))
Exemple #6
0
def add(dirpath, includes, ishandleurl=False):
    """处理历史文件"""
    filepaths = Tool.FileHelper.allfilefromdir(dirpath, includes)
    adddatacount = 0  #插入数据数量
    filecopycount = 0  #复制文件数量
    totalcount = len(filepaths)
    i = 1
    for filepath in filepaths:
        print("文件总数:%s;复制文件数量:%s;数据:%s;当前%s" %
              (totalcount, filecopycount, adddatacount, i))
        i = i + 1
        filehistory = handlefilepath(filepath)
        if not os.path.exists(filehistory.filepath):  # 不存在则复制
            shutil.copy(filepath, filehistory.filepath)
            filecopycount = filecopycount + 1
            print("从:%s到:%s" % (filepath, filehistory.filepath))
        Store.FileHistoryRepository().add(filehistory)
        if ishandleurl:
            #handleurl(filepath, filehistory.filepath)
            handleurlbymd5(filehistory.md5, filepath, filehistory.filepath)
        adddatacount = adddatacount + 1
    print("全部完成,文件总数:%s;复制文件数量:%s;数据:%s" %
          (totalcount, filecopycount, adddatacount))