You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.2 KiB
Python

2 years ago
import telebot
from typing import NoReturn
from time import sleep
from asyncio import sleep
import requests
import re
import pymysql,telegram
from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext
import requests
#tg机器人id
2 years ago
bot_api = "58023:AAH2DlZY-eRswzx_niNVeQ"
2 years ago
import pymysql #连接数据库
connect = pymysql.connect(host='127.0.0.1', # 本地数据库
user='duxiu',
2 years ago
password='KNFP5Zf7bM',
2 years ago
db='duxiu',
charset='utf8') #服务器名,账户,密码,数据库名称
db = connect.cursor()
def start(update: Update, context: CallbackContext):
update.message.reply_text('请输入读秀SS号,输入格式为:/ss 14061086')
def ss(update: Update, context: CallbackContext) -> None:
text = update.message.text
names = text.split(' ')
name = names[1]
content = '^[0-9]{8}$'
result = re.findall(content, str(name))
if len(result) != 0:
sql = "SELECT * FROM FileObject WHERE name LIKE '%" + name + "%';"
db.execute(sql)
result = db.fetchall()
if len(result) !=0:
fs_id = result[0][1]
ss = duxiu(fs_id)
update.message.reply_text(ss)
else:
update.message.reply_text("数据库没有该书集")
else:
update.message.reply_text("输入的读秀SS格式错误")
print(name)
print(ss)
#百度网盘连接生成功能
def duxiu(ss):
session = requests.session()
# BDUSS和STOKEN的值从cookies种获取
2 years ago
session.cookies["BDUSS"] = 'G2hIMmNTTHRVM283WTNmajFmMHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPVuj2P1bo9jY'
session.cookies["STOKEN"] = '12da7949ba2a7EI1QjBFQkQ0MkE4Qzg6U0w9MDpOUj0xMDpGRz0x&clienttype=0'
2 years ago
headerss = {
'Host': 'pan.baidu.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
}
response = session.get('https://pan.baidu.com/', headers=headerss)
if(not False):
pwd = 1123
form_data = {
'schannel': 4,
'channel_list': '[]',
'period': 7,
'pwd': pwd,
'fid_list': str([int(ss)]),
}
print(str([ss]))
# 补充cookie的值
headers = {
"Accept":"*/*" ,
"Accept-Encoding":"gzip, deflate, br" ,
"Accept-Language":"zh-CN,zh;q=0.9" ,
"Cache-Control":"no-cache" ,
"Connection":"keep-alive" ,
"Content-Length":"16930" ,
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8" ,
2 years ago
"Cookie":"newlogin=1; BAIDUID=80070C95EF42:FG=1; BDUSS=GhHLlyj2O5co9jR; BDUSS_BFESS=GhHLVYwemRLlyj2O5co9jR; ab_sr=1.0.1_MTU2ODJmYmQzYzcwODI4MmM3ZTc5YTE2OTNlNjBjZGRkZDY2ODE3ZWEyMmQyY2Q3MDhkNDg2ZjQxODZkMTJkNjU1ZWYxZjM2NGI0MmUyOTE3YTcxM2EwYTgyNWEwOWRjYTMyZTEzZTc1NTMxZTA4ZjgzNjNlMTliNWEzMjRkZTdmMzEzYmE2MmQ5Mjk4YWRlNmNjOTEwNjg4Y2Q3NGNiMQ==" ,
2 years ago
"Host":"pan.baidu.com" ,
"Origin":"https://pan.baidu.com" ,
"Pragma":"no-cache" ,
"Referer":"https://pan.baidu.com/disk/home?" ,
"Sec-Fetch-Dest":"empty" ,
"Sec-Fetch-Mode":"cors" ,
"Sec-Fetch-Site":"same-origin" ,
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36" ,
"X-Requested-With":"XMLHttpRequest"
}
responsess = session.post(url, headers=headers, data=form_data)
print(responsess.headers)
if(responsess.json()['errno'] == 0):
print({'errno': 0, 'err_msg': '创建分享链接成功!', 'info': {'link': responsess.json()['link'], 'pwd': pwd}})
return {'link': responsess.json()['link'], 'pwd': pwd}
else:
print( {'errno': 1, 'err_msg': '创建分享链接失败!', 'info': responsess.json()})
return "创建分享链接失败!"
def main() -> None:
updater = Updater(bot_api)
dispatcher = updater.dispatcher
# 机器人命令
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("ss", ss))
# 启动机器人,勿删
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()