pull/888/head
Celeter 4 years ago
parent aadbac59e6
commit 896741df80
  1. 114
      .github/scripts/lzy_web.py

@ -1,119 +1,99 @@
import requests, os, datetime, sys import requests, os, datetime, sys
# Cookie 中 phpdisk_info 的值
cookie_phpdisk_info = os.environ.get('phpdisk_info')
# Cookie 中 ylogin 的值
cookie_ylogin = os.environ.get('ylogin')
class lzyCloud(object): # 请求头
def __init__(self): headers = {
self._session = requests.Session()
self._timeout = 30 # 每个请求的超时(不包含下载响应体的用时)
self._doupload_url = 'https://pc.woozooo.com/doupload.php'
self._account_url = 'https://pc.woozooo.com/account.php'
self._cookies = None
self._headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45',
'Accept-Language': 'zh-CN,zh;q=0.9', 'Accept-Language': 'zh-CN,zh;q=0.9',
'Referer': 'https://pc.woozooo.com/account.php?action=login' 'Referer': 'https://pc.woozooo.com/account.php?action=login'
} }
# disable_warnings(InsecureRequestWarning) # 全局禁用 SSL 警告
# 小饼干
cookie = {
'ylogin': cookie_ylogin,
'phpdisk_info': cookie_phpdisk_info
}
# 日志打印 # 日志打印
def _log(self, msg): def log(msg):
utc_time = datetime.datetime.utcnow() utc_time = datetime.datetime.utcnow()
china_time = utc_time + datetime.timedelta(hours=8) china_time = utc_time + datetime.timedelta(hours=8)
print(f"[{china_time.strftime('%Y.%m.%d %H:%M:%S')}] {msg}") print(f"[{china_time.strftime('%Y.%m.%d %H:%M:%S')}] {msg}")
# get请求
def _get(self, url, **kwargs):
try:
kwargs.setdefault('timeout', self._timeout)
kwargs.setdefault('headers', self._headers)
return self._session.get(url, verify=True, **kwargs)
except (ConnectionError, requests.RequestException):
return None
# post请求
def _post(self, url, data, **kwargs):
try:
kwargs.setdefault('timeout', self._timeout)
kwargs.setdefault('headers', self._headers)
return self._session.post(url, data, verify=True, **kwargs)
except (ConnectionError, requests.RequestException):
return None
# 通过cookie登录 # 检查是否已登录
def login_by_cookie(self, cookies: dict) -> bool: def login_by_cookie():
self._cookies = cookies url_account = "https://pc.woozooo.com/account.php"
self._session.cookies.update(self._cookies) if cookie['phpdisk_info'] is None:
res = self._get(self._account_url) log('ERROR: 请指定 Cookie 中 phpdisk_info 的值!')
if not res:
self._log('登录失败,请重试')
return False return False
if cookie['ylogin'] is None:
log('ERROR: 请指定 Cookie 中 ylogin 的值!')
return False
res = requests.get(url_account, headers=headers, cookies=cookie, verify=True)
if '网盘用户登录' in res.text: if '网盘用户登录' in res.text:
self._log('登录失败,请更新Cookie') log('ERROR: 登录失败,请更新Cookie')
return False return False
else: else:
self._log('登录成功') log('登录成功')
return True return True
# 上传文件 # 上传文件
def _upload_file(self, file_dir, folder_id): def upload_file(file_dir, folder_id):
file_name = os.path.basename(file_dir) file_name = os.path.basename(file_dir)
self._headers['Referer'] = 'https://up.woozooo.com/mydisk.php?item=files&action=index&u=' + self._cookies.get( url_upload = "https://up.woozooo.com/fileup.php"
"ylogin") headers['Referer'] = f'https://up.woozooo.com/mydisk.php?item=files&action=index&u={cookie_ylogin}'
data = { post_data = {
"task": "1", "task": "1",
"folder_id": folder_id, "folder_id": folder_id,
"id": "WU_FILE_0", "id": "WU_FILE_0",
"name": file_name, "name": file_name,
} }
files = {'upload_file': (file_name, open(file_dir, "rb"), 'application/octet-stream')} files = {'upload_file': (file_name, open(file_dir, "rb"), 'application/octet-stream')}
res = self._post(self._doupload_url, data=data, files=files).json() res = requests.post(url_upload, data=post_data, files=files, headers=headers, cookies=cookie, timeout=120,
self._log(f"{file_dir} -> {res['info']}") verify=True).json()
log(f"{file_dir} -> {res['info']}")
return res['zt'] == 1 return res['zt'] == 1
# 上传文件夹内的文件 # 上传文件夹内的文件
def _upload_folder(self, folder_dir, folder_id): def upload_folder(folder_dir, folder_id):
file_list = os.listdir(folder_dir) file_list = os.listdir(folder_dir)
for file in file_list: for file in file_list:
path = os.path.join(folder_dir, file) path = os.path.join(folder_dir, file)
if os.path.isfile(path): if os.path.isfile(path):
self._upload_file(path, folder_id) upload_file(path, folder_id)
else: else:
self._upload_folder(path, folder_id) upload_folder(path, folder_id)
# 上传文件/文件夹内的文件 # 上传
def upload(self, dir, folder_id): def upload(dir, folder_id):
if dir is None: if dir is None:
self._log('请指定上传的文件路径') log('ERROR: 请指定上传的文件路径')
return return
if folder_id is None: if folder_id is None:
self._log('请指定蓝奏云的文件夹id') log('ERROR: 请指定蓝奏云的文件夹id')
return return
if os.path.isfile(dir): if os.path.isfile(dir):
self._upload_file(dir, str(folder_id)) upload_file(dir, str(folder_id))
else: else:
self._upload_folder(dir, str(folder_id)) upload_folder(dir, str(folder_id))
if __name__ == '__main__': if __name__ == '__main__':
argv = sys.argv[1:] argv = sys.argv[1:]
if len(argv) != 2: if len(argv) != 2:
print('参数错误,请以这种格式重新尝试\npython lzy_web.py 需上传的路径 蓝奏云文件夹id') log('ERROR: 参数错误,请以这种格式重新尝试\npython lzy_web.py 需上传的路径 蓝奏云文件夹id')
# 需上传的路径 # 需上传的路径
upload_path = argv[0] upload_path = argv[0]
# 蓝奏云文件夹id # 蓝奏云文件夹id
lzy_folder_id = argv[1] lzy_folder_id = argv[1]
if login_by_cookie():
# Cookie 中 phpdisk_info 的值 upload(upload_path, lzy_folder_id)
phpdisk_info = os.environ.get('phpdisk_info')
# Cookie 中 ylogin 的值
ylogin = os.environ.get('ylogin')
# 小饼干
cookie = {
'ylogin': ylogin,
'phpdisk_info': phpdisk_info
}
lzy = lzyCloud()
if lzy.login_by_cookie(cookie):
lzy.upload(upload_path, lzy_folder_id)
Loading…
Cancel
Save