commit 711df363adf98245a575bb0329e68b0b4c399bfc Author: roger_home_pc Date: Fri Aug 4 21:26:10 2023 +0800 第一次提交 diff --git a/cookie.txt b/cookie.txt new file mode 100644 index 0000000..6dc81b2 --- /dev/null +++ b/cookie.txt @@ -0,0 +1 @@ +Hm_lvt_7a3960b6f067eb0085b7f96ff5e660b0=1690080220,1690550836,1690723621,1690809059; ndut_fmt=0CB8F743B86D82140C03546BACAB8E27C63C6F0E4D04AA253D2F97753BAB5AA2; BDCLND=Kiz1b8Bpv31XBFDJNdGFjZSNEpvCREEMgiHA5oAF99k%3D; BDUSS=3dlMEhZLWtLS2tGeVh2T1ozYWtYaXdFTWV6QnRrYzByMEwzd2hWWmxkamd4dk5pRVFBQUFBJCQAAAAAAAAAAAEAAADgajfycm9nZXJzdW4wOTAxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOA5zGLgOcxid; BIDUPSID=2947C9BCCF77B5D4BFC420C602BE3DF5; PSTM=1658846657; ZFY=0Vc50oTr7EmlM6WxzWE2Eewo0ltT5VQJ2KG9s8DcdoY:C; MCITY=-131%3A; STOKEN=d598c65d443486ba06db34f988e6ac8d108c6b2e4f4eae47aeec796b8c487453; BAIDUID=8DC7F291FA0638DF89C98F0178FCDC7C:FG=1; BAIDUID_BFESS=8DC7F291FA0638DF89C98F0178FCDC7C:FG=1; PANWEB=1; newlogin=1; csrfToken=AqCSBjCRMfPdDqStzGsMcX8E; PANPSC=6335470297685612817%3AKkwrx6t0uHBNjb%2BA%2BPLlBZgtJeEFa7WQw1jWL8y1tqu8ztnSQmWL1wZuq6kOUHWC2ZacVotps30YgRTDIgwTn8ZIzuhpmLh6b55KeZe4CQBn3K3RJ8ZwedL9vR6DsgcTu1tPRVPr6y7%2FwyO%2B4eG7s0I0NZhR03fFuueAr2t%2FRhNXpcvfoZtUp%2B4PuTzNr1rr; ab_sr=1.0.1_ZjdjNGYzMjAwMjdhMGQ4M2VkMTEwYzkxZTk0YzQ2YjI5ZmFjMWQwMmE4MTBiNmZmM2MyMmY0YWNiMzJkYWQyZjU5NGY2YmVjZjA4MmY3MDA2NDM5YjdjNGU2YTA1YjYxMzBjMmUwNzAxOTA2NTU1MzVmODg0YmQ0MWZlZmJhYTI3NzBlYWE4ODRiMzdmYmFhOWYwZTExMDQyMGIxYWU3ZjY0M2Y3Nzg0ZWYzOGUwNTBmMGQ5MWU2Y2Y4OGM3Y2Yy \ No newline at end of file diff --git a/db.py b/db.py new file mode 100644 index 0000000..d28befc --- /dev/null +++ b/db.py @@ -0,0 +1,43 @@ +import pymysql +from pymysql.cursors import DictCursor +import datetime + +db_config = { + 'host': '192.168.66.101', + 'user': 'root', + 'password': 'Sxzgx1209', + 'database': 'scrapy' +} + + +class DbAction: + def __init__(self, end_date='today'): + self.conn = pymysql.Connection(**db_config) + self.cursor = self.conn.cursor(cursor=DictCursor) + self.date_list = self.get_date_list(end_date) + + def get_db_data(self): + query_sql = f"SELECT h.id, h.cate, h.date, h.`name`, h.save_link, h.`code`, h.unzip_pwd FROM scrapyh h WHERE h.date IN ({self.date_list});" + self.cursor.execute(query_sql) + return self.cursor.fetchall() + + @staticmethod + def get_date_list(_end_date): + date_list = [] + if _end_date == 'today': + date_list.append(f"'{datetime.date.strftime(datetime.date.today(), '%Y-%m-%d')}'") + else: + start_date = datetime.datetime.today() + end_date = datetime.datetime.strptime(_end_date, '%Y-%m-%d') + delta = datetime.timedelta(days=1) + while start_date > end_date: + date_list.append(f"'{datetime.datetime.strftime(start_date, '%Y-%m-%d')}'") + start_date = start_date - delta + print(date_list) + return ','.join(date_list) + + +if __name__ == '__main__': + db_action = DbAction('2023-07-28') + result = db_action.get_db_data() + print(result) diff --git a/main.py b/main.py new file mode 100644 index 0000000..e69de29 diff --git a/req.py b/req.py new file mode 100644 index 0000000..3be120e --- /dev/null +++ b/req.py @@ -0,0 +1,56 @@ +import requests +from retrying import retry + +requests.packages.urllib3.disable_warnings() + +# 静态变量 +BASE_URL = 'https://pan.baidu.com' +ERROR_CODES = { + 1: '链接失效,没获取到 shareid', + 2: '链接失效,没获取到 user_id', + 3: '链接失效,没获取到 fs_id', + '百度网盘-链接不存在': '链接失效,文件已经被删除或取消分享', + '百度网盘 请输入提取码': '链接错误,缺少提取码', + -9: '链接错误,提取码错误或验证已过期', + -62: '链接错误尝试次数过多,请手动转存或稍后再试', + 105: '链接错误,链接格式不正确', + -4: '转存失败,无效登录。请退出账号在其他地方的登录', + -6: '转存失败,请用浏览器无痕模式获取 Cookie', + 4: '转存失败,目录中已有同名文件或文件夹存在', + -8: '转存失败,目录中已有同名文件或文件夹存在', + 12: '转存失败,转存文件数超过限制', + -7: '转存失败,秒传文件名有非法字符', + 404: '转存失败,秒传无效', + 31190: '转存失败,秒传未生效', + 31039: '转存失败,秒传文件名冲突', + -10: '转存失败,容量不足', + 20: '转存失败,容量不足', + 0: '转存成功', +} + + +class ReqAction: + # 请求变量 + request_header = { + 'Host': 'pan.baidu.com', + 'Connection': 'keep-alive', + 'Upgrade-Insecure-Requests': '1', + 'Sec-Fetch-Dest': 'document', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', + 'Sec-Fetch-Site': 'same-site', + 'Sec-Fetch-Mode': 'navigate', + 'Referer': 'https://pan.baidu.com', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7,en-GB;q=0.6,ru;q=0.5', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36', + } + + def __init__(self): + sess = Request + + @retry(stop_max_attempt_number=3, wait_fixed=1000) + def get_bdstoken(self): + url = f'{BASE_URL}/api/gettemplatevariable?clienttype=0&app_id=250528&web=1&fields=[%22bdstoken%22,%22token%22,%22uk%22,%22isdocuser%22,%22servertime%22]' + response = self.session.get(url=url, headers=self.request_header, timeout=20, allow_redirects=True, + verify=False) + return response.json()['errno'] if response.json()['errno'] != 0 else response.json()['result']['bdstoken']