qrpa 1.0.34__py3-none-any.whl → 1.1.50__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qrpa/RateLimitedSender.py +45 -45
- qrpa/__init__.py +31 -26
- qrpa/db_migrator.py +600 -600
- qrpa/feishu_bot_app.py +267 -267
- qrpa/feishu_client.py +410 -0
- qrpa/feishu_logic.py +1443 -0
- qrpa/fun_base.py +339 -337
- qrpa/fun_excel.py +529 -61
- qrpa/fun_file.py +318 -318
- qrpa/fun_web.py +258 -148
- qrpa/fun_win.py +198 -198
- qrpa/mysql_module/__init__.py +0 -0
- qrpa/mysql_module/new_product_analysis_model.py +556 -0
- qrpa/mysql_module/shein_ledger_model.py +468 -0
- qrpa/mysql_module/shein_product_model.py +495 -0
- qrpa/mysql_module/shein_return_order_model.py +569 -0
- qrpa/mysql_module/shein_store_model.py +595 -0
- qrpa/shein_daily_report_model.py +375 -375
- qrpa/shein_excel.py +1248 -109
- qrpa/shein_lib.py +2333 -143
- qrpa/shein_mysql.py +92 -0
- qrpa/shein_sqlite.py +153 -153
- qrpa/shein_ziniao.py +529 -450
- qrpa/temu_chrome.py +56 -56
- qrpa/temu_excel.py +139 -139
- qrpa/temu_lib.py +156 -154
- qrpa/time_utils.py +87 -50
- qrpa/time_utils_example.py +243 -243
- qrpa/wxwork.py +318 -318
- {qrpa-1.0.34.dist-info → qrpa-1.1.50.dist-info}/METADATA +1 -1
- qrpa-1.1.50.dist-info/RECORD +33 -0
- qrpa-1.0.34.dist-info/RECORD +0 -24
- {qrpa-1.0.34.dist-info → qrpa-1.1.50.dist-info}/WHEEL +0 -0
- {qrpa-1.0.34.dist-info → qrpa-1.1.50.dist-info}/top_level.txt +0 -0
qrpa/temu_lib.py
CHANGED
|
@@ -1,154 +1,156 @@
|
|
|
1
|
-
from .fun_file import read_dict_from_file, write_dict_to_file, read_dict_from_file_ex, write_dict_to_file_ex
|
|
2
|
-
from .fun_base import log, send_exception, md5_string, get_safe_value
|
|
3
|
-
from .time_utils import TimeUtils
|
|
4
|
-
|
|
5
|
-
import json, requests, time, math
|
|
6
|
-
|
|
7
|
-
class TemuLib:
|
|
8
|
-
def __init__(self, config, mobile, password, web_page):
|
|
9
|
-
self.config = config
|
|
10
|
-
self.web_page = web_page
|
|
11
|
-
self.mobile = mobile
|
|
12
|
-
|
|
13
|
-
self.dict_mall = {}
|
|
14
|
-
self.cookie = self.doLoginToTemu(mobile, password)
|
|
15
|
-
|
|
16
|
-
# 主账户登录 返回Cookie
|
|
17
|
-
def doLoginToTemu(self, username, password):
|
|
18
|
-
cache_cookie = f'{self.config.auto_dir}/temu/cookie/cookie_{username}.json'
|
|
19
|
-
dict_cookie = read_dict_from_file(cache_cookie, 1)
|
|
20
|
-
if len(dict_cookie) > 0:
|
|
21
|
-
self.cookie = dict_cookie.get('cookie')
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
log(f'登录Temu账号: {username}')
|
|
25
|
-
|
|
26
|
-
"""使用 XPath 登录网站"""
|
|
27
|
-
# 导航到登录页面
|
|
28
|
-
self.web_page.goto("https://seller.kuajingmaihuo.com/login")
|
|
29
|
-
#
|
|
30
|
-
self.web_page.locator('//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
self.web_page.locator('//input[@id="
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
self.web_page.locator('//input[@
|
|
37
|
-
#
|
|
38
|
-
self.web_page.locator('//
|
|
39
|
-
#
|
|
40
|
-
self.web_page.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
self.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
1
|
+
from .fun_file import read_dict_from_file, write_dict_to_file, read_dict_from_file_ex, write_dict_to_file_ex
|
|
2
|
+
from .fun_base import log, send_exception, md5_string, get_safe_value
|
|
3
|
+
from .time_utils import TimeUtils
|
|
4
|
+
|
|
5
|
+
import json, requests, time, math
|
|
6
|
+
|
|
7
|
+
class TemuLib:
|
|
8
|
+
def __init__(self, config, mobile, password, web_page):
|
|
9
|
+
self.config = config
|
|
10
|
+
self.web_page = web_page
|
|
11
|
+
self.mobile = mobile
|
|
12
|
+
|
|
13
|
+
self.dict_mall = {}
|
|
14
|
+
self.cookie = self.doLoginToTemu(mobile, password)
|
|
15
|
+
|
|
16
|
+
# 主账户登录 返回Cookie
|
|
17
|
+
def doLoginToTemu(self, username, password):
|
|
18
|
+
cache_cookie = f'{self.config.auto_dir}/temu/cookie/cookie_{username}.json'
|
|
19
|
+
dict_cookie = read_dict_from_file(cache_cookie, 1)
|
|
20
|
+
if len(dict_cookie) > 0:
|
|
21
|
+
self.cookie = dict_cookie.get('cookie')
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
log(f'登录Temu账号: {username}')
|
|
25
|
+
|
|
26
|
+
"""使用 XPath 登录网站"""
|
|
27
|
+
# 导航到登录页面
|
|
28
|
+
self.web_page.goto("https://seller.kuajingmaihuo.com/login")
|
|
29
|
+
# fixed
|
|
30
|
+
self.web_page.locator('//div[text()="账号登录"]').click()
|
|
31
|
+
# 输入用户名
|
|
32
|
+
self.web_page.locator('//input[@id="usernameId"]').fill("")
|
|
33
|
+
self.web_page.locator('//input[@id="usernameId"]').fill(username)
|
|
34
|
+
# 输入密码
|
|
35
|
+
self.web_page.locator('//input[@id="passwordId"]').fill("")
|
|
36
|
+
self.web_page.locator('//input[@id="passwordId"]').fill(password)
|
|
37
|
+
# 勾选隐私政策(checkbox)
|
|
38
|
+
self.web_page.locator('//input[@type="checkbox"]/following-sibling::div').click() # 直接check不了 换成点击
|
|
39
|
+
# 点击登录按钮
|
|
40
|
+
self.web_page.locator('//button[span[text()="登录"]]').click()
|
|
41
|
+
# 等待登录完成(根据页面加载情况调整等待策略)
|
|
42
|
+
self.web_page.wait_for_load_state("load")
|
|
43
|
+
|
|
44
|
+
while True:
|
|
45
|
+
log('等待卖家中心出现')
|
|
46
|
+
try:
|
|
47
|
+
if self.web_page.locator('//div[text()="Temu商家中心"]').count() == 1:
|
|
48
|
+
log('卖家中心已出现')
|
|
49
|
+
break
|
|
50
|
+
if self.web_page.locator('//div[text()="Seller Central"]').count() == 1:
|
|
51
|
+
log('卖家中心已出现')
|
|
52
|
+
break
|
|
53
|
+
except Exception as e:
|
|
54
|
+
log(f"❌{e}")
|
|
55
|
+
time.sleep(1.5)
|
|
56
|
+
|
|
57
|
+
log("✅ 登录成功")
|
|
58
|
+
|
|
59
|
+
self.web_page.wait_for_load_state("load")
|
|
60
|
+
self.web_page.wait_for_timeout(3000)
|
|
61
|
+
cookies = self.web_page.context.cookies()
|
|
62
|
+
cookies_list = [cookie for cookie in cookies if '.kuajingmaihuo.com' in cookie['domain']]
|
|
63
|
+
self.cookie = '; '.join([f"{cookie['name']}={cookie['value']}" for cookie in cookies_list])
|
|
64
|
+
log(f'已获取self.cookie:', self.cookie)
|
|
65
|
+
write_dict_to_file(cache_cookie, {'cookie': self.cookie})
|
|
66
|
+
return self.cookie
|
|
67
|
+
|
|
68
|
+
def post_json(self, str_url, payload, mall_id=None):
|
|
69
|
+
global response
|
|
70
|
+
try:
|
|
71
|
+
headers = {
|
|
72
|
+
'content-type': 'application/json',
|
|
73
|
+
'priority' : 'u=1, i',
|
|
74
|
+
'referer' : 'https://seller.kuajingmaihuo.com/settle/site-main',
|
|
75
|
+
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
|
|
76
|
+
'Cookie' : self.cookie,
|
|
77
|
+
}
|
|
78
|
+
if mall_id:
|
|
79
|
+
headers.update({'mallid': f"{mall_id}"})
|
|
80
|
+
response = requests.post(str_url, headers=headers, data=json.dumps(payload))
|
|
81
|
+
response.raise_for_status() # 如果响应不正常,会抛出异常
|
|
82
|
+
|
|
83
|
+
response_text = response.json()
|
|
84
|
+
error_code = response_text.get('error_code') or response_text.get('errorCode')
|
|
85
|
+
if error_code != 1000000:
|
|
86
|
+
raise send_exception(response_text)
|
|
87
|
+
return response.json() # 直接返回 JSON 格式的数据
|
|
88
|
+
except:
|
|
89
|
+
raise send_exception()
|
|
90
|
+
|
|
91
|
+
def get_shop_list(self):
|
|
92
|
+
log(f'获取店铺列表')
|
|
93
|
+
global DictMall
|
|
94
|
+
url = "https://seller.kuajingmaihuo.com/bg/quiet/api/mms/userInfo"
|
|
95
|
+
response_text = self.post_json(url, {})
|
|
96
|
+
|
|
97
|
+
company_list = response_text['result']['companyList']
|
|
98
|
+
mall_list = []
|
|
99
|
+
for company in company_list:
|
|
100
|
+
mallList = company['malInfoList']
|
|
101
|
+
# shop_list = [['店铺ID', '店铺名称', '主账号', '店铺类型']]
|
|
102
|
+
for mall in mallList:
|
|
103
|
+
mall_id = str(mall['mallId'])
|
|
104
|
+
mall_name = str(mall['mallName'])
|
|
105
|
+
shop_info = [mall_id, mall_name, self.mobile, '半托管' if mall['isSemiManagedMall'] else '全托管']
|
|
106
|
+
write_dict_to_file_ex(self.config.temu_store_info, {mall_id: shop_info}, [mall_id])
|
|
107
|
+
|
|
108
|
+
self.dict_mall[str(mall['mallId'])] = mall['mallName']
|
|
109
|
+
|
|
110
|
+
if not mall['isSemiManagedMall']:
|
|
111
|
+
mall_list.append([str(mall['mallId']), mall['mallName'], '', self.mobile])
|
|
112
|
+
|
|
113
|
+
return mall_list
|
|
114
|
+
|
|
115
|
+
def get_funds_info(self, mall_id):
|
|
116
|
+
log(f'获取 {self.dict_mall[mall_id]} 资金信息')
|
|
117
|
+
url = "https://seller.kuajingmaihuo.com/api/merchant/payment/account/amount/info"
|
|
118
|
+
response_text = self.post_json(url, {}, mall_id)
|
|
119
|
+
total_amount = response_text.get('result').get('totalAmount')
|
|
120
|
+
available_amount = response_text.get('result').get('availableBalance')
|
|
121
|
+
|
|
122
|
+
NotifyItem = [self.dict_mall[mall_id], total_amount, available_amount, '', TimeUtils.current_datetime()]
|
|
123
|
+
|
|
124
|
+
cache_file = f'{self.config.auto_dir}/temu/cache/funds_{TimeUtils.today_date()}.json'
|
|
125
|
+
write_dict_to_file_ex(cache_file, {mall_id: NotifyItem}, [mall_id])
|
|
126
|
+
|
|
127
|
+
return NotifyItem
|
|
128
|
+
|
|
129
|
+
def list_warehouse(self, mall_id, mall_name):
|
|
130
|
+
log(f'获取店铺 {mall_name} 销售商品列表 第1页')
|
|
131
|
+
url = "https://seller.kuajingmaihuo.com/marvel-mms/cn/api/kiana/venom/sales/management/listWarehouse"
|
|
132
|
+
payload = {
|
|
133
|
+
"pageNo" : 1,
|
|
134
|
+
"pageSize" : 40,
|
|
135
|
+
"isLack" : 0,
|
|
136
|
+
"selectStatusList" : [12], # 12 是已加入站点
|
|
137
|
+
"priceAdjustRecentDays": 30 # 近30日价格调整
|
|
138
|
+
}
|
|
139
|
+
response_text = self.post_json(url, payload, mall_id)
|
|
140
|
+
|
|
141
|
+
total = response_text['result']['total']
|
|
142
|
+
subOrderListCount = len(response_text['result']['subOrderList'])
|
|
143
|
+
totalPage = math.ceil(total / subOrderListCount) if subOrderListCount else 0
|
|
144
|
+
subOrderList = response_text['result']['subOrderList']
|
|
145
|
+
|
|
146
|
+
for page in range(2, totalPage + 1):
|
|
147
|
+
log(f'获取店铺{mall_name}销售商品列表 第{page}/{totalPage}页')
|
|
148
|
+
payload['pageNo'] = page
|
|
149
|
+
response_text = self.post_json(url, payload, mall_id)
|
|
150
|
+
subOrderList += response_text['result']['subOrderList']
|
|
151
|
+
time.sleep(0.3)
|
|
152
|
+
|
|
153
|
+
cache_file = f'{self.config.auto_dir}/temu/cache/warehouse_list_{TimeUtils.today_date()}.json'
|
|
154
|
+
write_dict_to_file_ex(cache_file, {mall_id: subOrderList}, [mall_id])
|
|
155
|
+
|
|
156
|
+
return subOrderList
|