コード例 #1
0
def api_checkbenben():
    uid = request.args.get('uid', -1, type=int)
    page = request.args.get('page', 1, type=int)
    headers = {
        'User-Agent':
        "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
    }
    try:
        benbens = requests.get(
            'https://www.luogu.com.cn/api/feed/list?user={}&page={}'.format(
                uid, page),
            headers=headers).json()
    except:
        time.sleep(5)
        benbens = requests.get(
            'https://www.luogu.com.cn/api/feed/list?user={}&page={}'.format(
                uid, page),
            headers=headers).json()
    benbens = benbens['feeds']['result']
    cur = datetime.datetime.now()
    cnt = 0
    for i in benbens[::-1]:
        text = markdown.markdown(i['content'])
        username = i['user']['name']
        stime = datetime.datetime.fromtimestamp(i['time'])
        if BenBen.query.filter_by(uid=uid, time=stime).all():
            continue
        abb = BenBen()
        abb.text = text.replace('<p>', "").replace('</p>', "")
        abb.username = username
        abb.uid = uid
        abb.time = stime
        abb.lid = i['id']
        user = LuoguUser.query.filter_by(uid=uid).first()
        if user:
            user.benbens.append(abb)
            if user.username != username:
                user.username = username
        else:
            user = LuoguUser(username=username, uid=uid)
            db.session.add(user)
            user.benbens.append(abb)
        db.session.add(abb)
        db.session.commit()
        if stime.date() == cur.date():
            cnt += 1
    return str(cnt), 200, {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Headers":
        "Origin, X-Requested-With, Content-Type, Accept",
        'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS'
    }
コード例 #2
0
ファイル: app.py プロジェクト: bear-good/ben-ben-spider
def fakebenbens(count):
    click.echo('开始生成')
    count = int(count)
    benbenslist = ['I AK IOI', '洛谷真棒!', '咕咕咕', '冒泡', 'kkkAKIOI']
    userlist = LuoguUser.query.all()
    for i in range(count):
        b = random.choice(benbenslist)
        user = random.choice(userlist)
        abb = BenBen()
        abb.text = b
        abb.username = user.username
        abb.uid = user.uid
        abb.time = datetime.datetime.now()
        user.benbens.append(abb)
        db.session.add(abb)
        db.session.commit()
        click.echo("成功生成了一条")
コード例 #3
0
def apipbbpost():
    uid = request.form.get("uid")
    token = request.form.get("token")
    user = LuoguUser.query.filter(LuoguUser.uid == uid).first()
    if not user:
        return "不存在的用户", 406
    if user.ptoken != token:
        return "token 错误", 403
    text = request.form.get("text")
    if text.isspace() or len(text) == 0:
        return "禁止空白", 406
    if len(text) >= 100:
        return "禁止过长", 406
    nbb = BenBen()
    nbb.md_code = text
    nbb.text = markdown.markdown(text).replace('<p>', "").replace('</p>', "")
    nbb.uid = uid
    nbb.username = user.username
    nbb.time = datetime.datetime.utcnow() + datetime.timedelta(hours=8)
    user.benbens.append(nbb)
    db.session.add(nbb)
    db.session.commit()
    return jsonify({"status": "succeed", "message": "发送成功"})
コード例 #4
0
ファイル: app.py プロジェクト: bear-good/ben-ben-spider
def api_checkbenben():
    uid = request.args.get('uid', -1, type=int)
    headers = {
        'User-Agent':
        "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
    }
    benbens = requests.get(
        'https://www.luogu.com.cn/api/feed/list?user={}'.format(uid),
        headers=headers).json()
    benbens = benbens['feeds']['result']
    cur = datetime.datetime.now()
    cnt = 0
    for i in benbens[::-1]:
        text = markdown.markdown(i['content'])
        username = i['user']['name']
        stime = datetime.datetime.fromtimestamp(i['time'])
        if BenBen.query.filter_by(uid=uid, time=stime).all():
            continue
        abb = BenBen()
        abb.text = text.replace('<p>', "").replace('</p>', "")
        abb.username = username
        abb.uid = uid
        abb.time = stime
        user = LuoguUser.query.filter_by(uid=uid).first()
        if user:
            user.benbens.append(abb)
            if user.username != username:
                user.username = username
        else:
            user = LuoguUser(username=username, uid=uid)
            db.session.add(user)
            user.benbens.append(abb)
        db.session.add(abb)
        db.session.commit()
        if stime.date() == cur.date():
            cnt += 1
    return str(cnt)