コード例 #1
0
def get_proxy():
    row = ProxyModel.select().order_by(-ProxyModel.score).first()
    item = dict()
    for k, v in row.__data__.items():
        if isinstance(v, datetime):
            v = v.strftime("%Y-%m-%d %H:%M:%S")
        item[k] = v

    return jsonify(item)
コード例 #2
0
def get_proxy_list(count):
    rows = ProxyModel.select().order_by(-ProxyModel.score).limit(count)

    lst = []
    for row in rows:
        item = dict()

        for k, v in row.__data__.items():
            if isinstance(v, datetime):
                v = v.strftime("%Y-%m-%d %H:%M:%S")
            item[k] = v
        lst.append(item)

    return jsonify(lst)
コード例 #3
0
def check_all():
    rows = ProxyModel.select().order_by(ProxyModel.update_time).limit(10)
    for row in rows:
        proxy = "{}:{}".format(row.ip, row.port)
        status = get_status(proxy)
        print(row.id, proxy, status, row.source)

        if status == 200:
            score = int(row.score) + 1
        else:
            score = int(row.score) - 1

        ProxyModel.update(
            update_time=datetime.now(),
            score=score).where(ProxyModel.id == row.id).execute()

        if score < MIN_SCORE:
            ret = ProxyModel.delete().where(ProxyModel.id == row.id).execute()
            print("delete ret: %s" % ret)