qrpa 1.1.79__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.
Potentially problematic release.
This version of qrpa might be problematic. Click here for more details.
- qrpa/RateLimitedSender.py +45 -0
- qrpa/__init__.py +31 -0
- qrpa/db_migrator.py +601 -0
- qrpa/feishu_bot_app.py +607 -0
- qrpa/feishu_client.py +410 -0
- qrpa/feishu_logic.py +1443 -0
- qrpa/fun_base.py +339 -0
- qrpa/fun_excel.py +3470 -0
- qrpa/fun_file.py +319 -0
- qrpa/fun_web.py +473 -0
- qrpa/fun_win.py +198 -0
- 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_ledger_month_report_model.py +599 -0
- qrpa/mysql_module/shein_product_model.py +495 -0
- qrpa/mysql_module/shein_return_order_model.py +776 -0
- qrpa/mysql_module/shein_store_model.py +595 -0
- qrpa/mysql_module/shein_supplier_info_model.py +554 -0
- qrpa/mysql_module/shein_wallet_model.py +638 -0
- qrpa/shein_daily_report_model.py +375 -0
- qrpa/shein_excel.py +3809 -0
- qrpa/shein_lib.py +5780 -0
- qrpa/shein_mysql.py +106 -0
- qrpa/shein_sqlite.py +154 -0
- qrpa/shein_ziniao.py +531 -0
- qrpa/temu_chrome.py +56 -0
- qrpa/temu_excel.py +139 -0
- qrpa/temu_lib.py +156 -0
- qrpa/time_utils.py +882 -0
- qrpa/time_utils_example.py +243 -0
- qrpa/wxwork.py +318 -0
- qrpa-1.1.79.dist-info/METADATA +9 -0
- qrpa-1.1.79.dist-info/RECORD +36 -0
- qrpa-1.1.79.dist-info/WHEEL +5 -0
- qrpa-1.1.79.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"""
|
|
2
|
+
时间工具模块使用示例
|
|
3
|
+
展示如何使用 time_utils.py 中的各种时间相关函数
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from time_utils import TimeUtils, today_date, get_yesterday, get_current_year
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def example_basic_usage():
|
|
10
|
+
"""基础使用示例"""
|
|
11
|
+
print("=== 基础使用示例 ===")
|
|
12
|
+
|
|
13
|
+
# 获取当前时间信息
|
|
14
|
+
print(f"当前日期: {today_date()}")
|
|
15
|
+
print(f"昨天: {get_yesterday()}")
|
|
16
|
+
print(f"当前年份: {get_current_year()}")
|
|
17
|
+
print(f"当前周数: {TimeUtils.get_week_num()}")
|
|
18
|
+
print(f"当前时间段: {TimeUtils.get_period()}")
|
|
19
|
+
print(f"中文星期: {TimeUtils.get_chinese_weekday(today_date())}")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def example_date_ranges():
|
|
23
|
+
"""日期范围计算示例"""
|
|
24
|
+
print("\n=== 日期范围计算示例 ===")
|
|
25
|
+
|
|
26
|
+
# 获取过去7天的日期范围
|
|
27
|
+
start, end = TimeUtils.get_past_7_days_range()
|
|
28
|
+
print(f"过去7天范围: {start} 到 {end}")
|
|
29
|
+
|
|
30
|
+
# 获取过去7天的日期列表
|
|
31
|
+
dates = TimeUtils.get_past_7_days_list()
|
|
32
|
+
print(f"过去7天列表: {dates}")
|
|
33
|
+
|
|
34
|
+
# 获取指定日期范围
|
|
35
|
+
date_list = TimeUtils.date_range('2025-01-01', '2025-01-05')
|
|
36
|
+
print(f"2025年1月1-5日: {date_list}")
|
|
37
|
+
|
|
38
|
+
# 获取上个月范围
|
|
39
|
+
last_month_start, last_month_end = TimeUtils.get_last_month_range()
|
|
40
|
+
print(f"上个月范围: {last_month_start} 到 {last_month_end}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def example_timestamp_conversion():
|
|
44
|
+
"""时间戳转换示例"""
|
|
45
|
+
print("\n=== 时间戳转换示例 ===")
|
|
46
|
+
|
|
47
|
+
from datetime import datetime
|
|
48
|
+
|
|
49
|
+
# 获取当前时间戳
|
|
50
|
+
current_ts = int(datetime.now().timestamp() * 1000)
|
|
51
|
+
print(f"当前时间戳: {current_ts}")
|
|
52
|
+
|
|
53
|
+
# 时间戳转字符串
|
|
54
|
+
time_str = TimeUtils.convert_timestamp_to_str(current_ts)
|
|
55
|
+
print(f"时间戳转字符串: {time_str}")
|
|
56
|
+
|
|
57
|
+
# 时间戳转日期
|
|
58
|
+
date_str = TimeUtils.convert_timestamp_to_date(current_ts)
|
|
59
|
+
print(f"时间戳转日期: {date_str}")
|
|
60
|
+
|
|
61
|
+
# 获取指定日期的开始和结束时间戳
|
|
62
|
+
start_ts = TimeUtils.get_start_timestamps('2025-01-01')
|
|
63
|
+
end_ts = TimeUtils.get_end_timestamps('2025-01-01')
|
|
64
|
+
print(f"2025-01-01 开始时间戳: {start_ts}")
|
|
65
|
+
print(f"2025-01-01 结束时间戳: {end_ts}")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def example_date_comparison():
|
|
69
|
+
"""日期比较示例"""
|
|
70
|
+
print("\n=== 日期比较示例 ===")
|
|
71
|
+
|
|
72
|
+
# 判断日期是否大于等于今天
|
|
73
|
+
is_future = TimeUtils.is_date_greater_or_equal('2025-12-31')
|
|
74
|
+
print(f"2025-12-31 是否大于等于今天: {is_future}")
|
|
75
|
+
|
|
76
|
+
# 判断是否是昨天
|
|
77
|
+
is_yesterday = TimeUtils.is_yesterday_date('2025-01-01')
|
|
78
|
+
print(f"2025-01-01 是否是昨天: {is_yesterday}")
|
|
79
|
+
|
|
80
|
+
# 判断时间是否在指定月份
|
|
81
|
+
in_month = TimeUtils.is_in_month('2025-01-15', 1)
|
|
82
|
+
print(f"2025-01-15 是否在1月: {in_month}")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def example_date_formatting():
|
|
86
|
+
"""日期格式化示例"""
|
|
87
|
+
print("\n=== 日期格式化示例 ===")
|
|
88
|
+
|
|
89
|
+
# 日期格式转换
|
|
90
|
+
date_with_slash = TimeUtils.date_trans('2025-01-01')
|
|
91
|
+
print(f"2025-01-01 转换为: {date_with_slash}")
|
|
92
|
+
|
|
93
|
+
# 跨平台格式化
|
|
94
|
+
cross_platform = TimeUtils.format_date_cross_platform('2025-01-01')
|
|
95
|
+
print(f"跨平台格式化: {cross_platform}")
|
|
96
|
+
|
|
97
|
+
# 时间字符串转日期
|
|
98
|
+
date_only = TimeUtils.convert_datetime_to_date('2025-01-01 12:30:45')
|
|
99
|
+
print(f"时间字符串转日期: {date_only}")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def example_advanced_usage():
|
|
103
|
+
"""高级使用示例"""
|
|
104
|
+
print("\n=== 高级使用示例 ===")
|
|
105
|
+
|
|
106
|
+
# 获取过去第n天的日期
|
|
107
|
+
past_5th_day = TimeUtils.get_past_nth_day(5)
|
|
108
|
+
print(f"过去第5天: {past_5th_day}")
|
|
109
|
+
|
|
110
|
+
# 获取过去n天的日期列表
|
|
111
|
+
past_10_days = TimeUtils.get_past_n_days_list(10)
|
|
112
|
+
print(f"过去10天列表: {past_10_days}")
|
|
113
|
+
|
|
114
|
+
# 获取从本月第一天到昨天的日期列表
|
|
115
|
+
month_dates = TimeUtils.get_dates_from_first_of_month_to_yesterday()
|
|
116
|
+
print(f"本月到昨天的日期: {month_dates}")
|
|
117
|
+
|
|
118
|
+
# 获取上个月的时间范围(字符串格式)
|
|
119
|
+
last_month_start_str, last_month_end_str = TimeUtils.get_last_month_range_time_str()
|
|
120
|
+
print(f"上个月时间范围: {last_month_start_str} 到 {last_month_end_str}")
|
|
121
|
+
|
|
122
|
+
# 获取上个月的时间范围(时间戳格式)
|
|
123
|
+
last_month_start_ts, last_month_end_ts = TimeUtils.get_last_month_range_time()
|
|
124
|
+
print(f"上个月时间戳范围: {last_month_start_ts} 到 {last_month_end_ts}")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def example_file_time():
|
|
128
|
+
"""文件时间相关示例"""
|
|
129
|
+
print("\n=== 文件时间相关示例 ===")
|
|
130
|
+
|
|
131
|
+
import os
|
|
132
|
+
|
|
133
|
+
# 创建一个临时文件用于测试
|
|
134
|
+
test_file = "test_file.txt"
|
|
135
|
+
with open(test_file, 'w') as f:
|
|
136
|
+
f.write("test content")
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
# 获取文件修改时间
|
|
140
|
+
file_mtime = TimeUtils.get_file_mtime(test_file)
|
|
141
|
+
print(f"文件修改时间: {file_mtime}")
|
|
142
|
+
|
|
143
|
+
# 获取文件修改时间(datetime对象)
|
|
144
|
+
file_mtime_dt = TimeUtils.get_file_mtime(test_file, to_str=False)
|
|
145
|
+
print(f"文件修改时间(datetime): {file_mtime_dt}")
|
|
146
|
+
|
|
147
|
+
finally:
|
|
148
|
+
# 清理测试文件
|
|
149
|
+
if os.path.exists(test_file):
|
|
150
|
+
os.remove(test_file)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def example_weekday_functions():
|
|
154
|
+
"""星期相关函数示例"""
|
|
155
|
+
print("\n=== 星期相关函数示例 ===")
|
|
156
|
+
|
|
157
|
+
# 获取中文星期
|
|
158
|
+
weekday_cn = TimeUtils.get_chinese_weekday('2025-01-01')
|
|
159
|
+
print(f"2025-01-01 的中文星期: {weekday_cn}")
|
|
160
|
+
|
|
161
|
+
# 获取简短星期名称
|
|
162
|
+
weekday_short = TimeUtils.get_weekday_name('2025-01-01')
|
|
163
|
+
print(f"2025-01-01 的简短星期: {weekday_short}")
|
|
164
|
+
|
|
165
|
+
# 获取当前周数
|
|
166
|
+
week_num = TimeUtils.get_week_num()
|
|
167
|
+
print(f"当前是第 {week_num} 周")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def example_period_functions():
|
|
171
|
+
"""时间段相关函数示例"""
|
|
172
|
+
print("\n=== 时间段相关函数示例 ===")
|
|
173
|
+
|
|
174
|
+
# 获取当前时间段(中文)
|
|
175
|
+
period_cn = TimeUtils.get_period()
|
|
176
|
+
print(f"当前时间段(中文): {period_cn}")
|
|
177
|
+
|
|
178
|
+
# 获取当前时间段(英文)
|
|
179
|
+
period_en = TimeUtils.get_period2()
|
|
180
|
+
print(f"当前时间段(英文): {period_en}")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def example_year_month_functions():
|
|
184
|
+
"""年月相关函数示例"""
|
|
185
|
+
print("\n=== 年月相关函数示例 ===")
|
|
186
|
+
|
|
187
|
+
# 获取当前年份
|
|
188
|
+
current_year = TimeUtils.get_current_year()
|
|
189
|
+
print(f"当前年份: {current_year}")
|
|
190
|
+
|
|
191
|
+
# 获取当前月份
|
|
192
|
+
current_month = TimeUtils.get_current_month()
|
|
193
|
+
print(f"当前月份: {current_month}")
|
|
194
|
+
|
|
195
|
+
# 获取上个月
|
|
196
|
+
last_month = TimeUtils.get_last_month()
|
|
197
|
+
print(f"上个月: {last_month}")
|
|
198
|
+
|
|
199
|
+
# 获取当前年份范围
|
|
200
|
+
year_start, year_end = TimeUtils.get_current_year_range()
|
|
201
|
+
print(f"当前年份范围: {year_start} 到 {year_end}")
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def example_relative_dates():
|
|
205
|
+
"""相对日期函数示例"""
|
|
206
|
+
print("\n=== 相对日期函数示例 ===")
|
|
207
|
+
|
|
208
|
+
# 获取昨天
|
|
209
|
+
yesterday = TimeUtils.get_yesterday()
|
|
210
|
+
print(f"昨天: {yesterday}")
|
|
211
|
+
|
|
212
|
+
# 获取前天
|
|
213
|
+
before_yesterday = TimeUtils.before_yesterday()
|
|
214
|
+
print(f"前天: {before_yesterday}")
|
|
215
|
+
|
|
216
|
+
# 获取明天
|
|
217
|
+
tomorrow = TimeUtils.tomorrow_date()
|
|
218
|
+
print(f"明天: {tomorrow}")
|
|
219
|
+
|
|
220
|
+
# 基于指定日期获取昨天
|
|
221
|
+
yesterday_from_date = TimeUtils.get_yesterday('20250101')
|
|
222
|
+
print(f"基于2025-01-01的昨天: {yesterday_from_date}")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if __name__ == "__main__":
|
|
226
|
+
"""运行所有示例"""
|
|
227
|
+
print("时间工具模块使用示例")
|
|
228
|
+
print("=" * 50)
|
|
229
|
+
|
|
230
|
+
example_basic_usage()
|
|
231
|
+
example_date_ranges()
|
|
232
|
+
example_timestamp_conversion()
|
|
233
|
+
example_date_comparison()
|
|
234
|
+
example_date_formatting()
|
|
235
|
+
example_advanced_usage()
|
|
236
|
+
example_file_time()
|
|
237
|
+
example_weekday_functions()
|
|
238
|
+
example_period_functions()
|
|
239
|
+
example_year_month_functions()
|
|
240
|
+
example_relative_dates()
|
|
241
|
+
|
|
242
|
+
print("\n" + "=" * 50)
|
|
243
|
+
print("所有示例运行完成!")
|
qrpa/wxwork.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
-------------------------------------------------
|
|
4
|
+
@version : v1.0
|
|
5
|
+
@author : qsir
|
|
6
|
+
@contact : qsir@vxnote.com
|
|
7
|
+
@software : PyCharm
|
|
8
|
+
@filename : wxwork.py
|
|
9
|
+
@create time: 2025/08/03
|
|
10
|
+
@modify time: 2025/08/03
|
|
11
|
+
@describe :
|
|
12
|
+
-------------------------------------------------
|
|
13
|
+
"""
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import hashlib
|
|
17
|
+
import base64
|
|
18
|
+
import requests
|
|
19
|
+
from requests_toolbelt import MultipartEncoder
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
|
|
22
|
+
# 通过企微群机器人发送消息
|
|
23
|
+
class WxWorkBot:
|
|
24
|
+
def __init__(self, key):
|
|
25
|
+
self.key = key
|
|
26
|
+
|
|
27
|
+
def upload_media(self, filepath):
|
|
28
|
+
"""
|
|
29
|
+
上传临时素材,给企微群里发文件消息时需要先将文件上传至企微临时素材中
|
|
30
|
+
:param filepath:
|
|
31
|
+
:return: 临时素材的media_id
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
headers = {
|
|
35
|
+
'Content-Type': 'multipart/form-data',
|
|
36
|
+
}
|
|
37
|
+
with open(filepath, 'rb') as f:
|
|
38
|
+
files = {
|
|
39
|
+
'media': (os.path.basename(filepath), f.read())
|
|
40
|
+
}
|
|
41
|
+
response = requests.post(
|
|
42
|
+
f'https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key={self.key}&type=file',
|
|
43
|
+
headers=headers, files=files)
|
|
44
|
+
response_text = json.loads(response.text)
|
|
45
|
+
if str(response_text.get('errcode')) != '0':
|
|
46
|
+
raise Exception(response_text)
|
|
47
|
+
if response.status_code == 200:
|
|
48
|
+
result = json.loads(response.text)
|
|
49
|
+
return result['media_id']
|
|
50
|
+
else:
|
|
51
|
+
print("HTTP Error:", response.status_code)
|
|
52
|
+
return None
|
|
53
|
+
except Exception as err:
|
|
54
|
+
raise Exception("upload_media error", err)
|
|
55
|
+
|
|
56
|
+
def send_file(self, file_path):
|
|
57
|
+
if not os.path.exists(file_path):
|
|
58
|
+
print('文件不存在: ', file_path)
|
|
59
|
+
return
|
|
60
|
+
"""
|
|
61
|
+
发送文件到群里
|
|
62
|
+
:param file_path:
|
|
63
|
+
:return:
|
|
64
|
+
"""
|
|
65
|
+
media_id = self.upload_media(file_path)
|
|
66
|
+
data = {
|
|
67
|
+
"msgtype": "file",
|
|
68
|
+
"file" : {
|
|
69
|
+
"media_id": media_id
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return self.send_msg(data)
|
|
73
|
+
|
|
74
|
+
def send_text(self, content, mentioned_list=None, mentioned_mobile_list=None):
|
|
75
|
+
"""
|
|
76
|
+
发送文本消息
|
|
77
|
+
:param content:
|
|
78
|
+
:param mentioned_list: 需要@的人userid
|
|
79
|
+
:param mentioned_mobile_list: 需要@的人手机号
|
|
80
|
+
:return:
|
|
81
|
+
"""
|
|
82
|
+
data = {
|
|
83
|
+
"msgtype": "text",
|
|
84
|
+
"text" : {
|
|
85
|
+
"content": content
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if mentioned_list is not None and mentioned_list:
|
|
89
|
+
data['text'].update({"mentioned_list": mentioned_list})
|
|
90
|
+
if mentioned_mobile_list is not None and mentioned_mobile_list:
|
|
91
|
+
data['text'].update({"mentioned_mobile_list": mentioned_mobile_list})
|
|
92
|
+
|
|
93
|
+
self.send_msg(data)
|
|
94
|
+
|
|
95
|
+
def send_markdown(self, content):
|
|
96
|
+
"""
|
|
97
|
+
发送Markdown消息
|
|
98
|
+
:param content:
|
|
99
|
+
:return:
|
|
100
|
+
"""
|
|
101
|
+
data = {
|
|
102
|
+
"msgtype" : "markdown",
|
|
103
|
+
"markdown": {
|
|
104
|
+
"content": content
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
self.send_msg(data)
|
|
108
|
+
|
|
109
|
+
def send_notify(self, title, sub_title_list, data_list):
|
|
110
|
+
"""
|
|
111
|
+
发送Markdown消息
|
|
112
|
+
:param content:
|
|
113
|
+
:return:
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
current_date = datetime.now().strftime("%Y-%m-%d")
|
|
117
|
+
header = f"{current_date} {title}\n\n"
|
|
118
|
+
|
|
119
|
+
arr_color = ['warning', 'info', 'warning']
|
|
120
|
+
arr_sub_header = [f"<font color='{arr_color[index]}'>{title}</font>" for index, title in enumerate(sub_title_list)]
|
|
121
|
+
sub_header = "\t".join(arr_sub_header) + "\n\n"
|
|
122
|
+
|
|
123
|
+
# 获取每个元素的行索引和列索引
|
|
124
|
+
arr_content = [
|
|
125
|
+
[
|
|
126
|
+
f'{value}' if col_idx == 0 else f"<font color='{arr_color[col_idx - 1]}'>{value}</font>"
|
|
127
|
+
for col_idx, value in enumerate(row)
|
|
128
|
+
] # 每行的元素组成一个子列表
|
|
129
|
+
for row_idx, row in enumerate(data_list) # 外层循环控制行
|
|
130
|
+
]
|
|
131
|
+
# 将二维数组转换为字符串
|
|
132
|
+
content = "\n".join(
|
|
133
|
+
# 对每行的元素列表使用 join(),用 \t 连接
|
|
134
|
+
"\t".join(row) for row in arr_content
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
data = {
|
|
138
|
+
"msgtype" : "markdown",
|
|
139
|
+
"markdown": {
|
|
140
|
+
"content": header + sub_header + content
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
self.send_msg(data)
|
|
144
|
+
|
|
145
|
+
def send_img(self, img_path):
|
|
146
|
+
"""
|
|
147
|
+
发送图片消息
|
|
148
|
+
图片(base64编码前)最大不能超过2M,支持JPG,PNG格式
|
|
149
|
+
:param img_path:
|
|
150
|
+
:return:
|
|
151
|
+
"""
|
|
152
|
+
data = {
|
|
153
|
+
"msgtype": "image",
|
|
154
|
+
"image" : {
|
|
155
|
+
"base64": self.img_to_base64(img_path),
|
|
156
|
+
"md5" : self.img_to_md5(img_path)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
self.send_msg(data)
|
|
160
|
+
|
|
161
|
+
def send_news(self, title, description, url, picurl):
|
|
162
|
+
"""
|
|
163
|
+
发送图文消息
|
|
164
|
+
:param title: 标题
|
|
165
|
+
:param description: 描述
|
|
166
|
+
:param url: 跳转URL
|
|
167
|
+
:param picurl: 图文图片地址
|
|
168
|
+
:return:
|
|
169
|
+
"""
|
|
170
|
+
data = {
|
|
171
|
+
"msgtype": "news",
|
|
172
|
+
"news" : {
|
|
173
|
+
"articles": [
|
|
174
|
+
{
|
|
175
|
+
"title" : title,
|
|
176
|
+
"description": description,
|
|
177
|
+
"url" : url,
|
|
178
|
+
"picurl" : picurl
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
self.send_msg(data)
|
|
184
|
+
|
|
185
|
+
def send_msg(self, data):
|
|
186
|
+
"""
|
|
187
|
+
发送机器人通用消息到企微群
|
|
188
|
+
:param data: 消息内容json数据
|
|
189
|
+
:return:
|
|
190
|
+
"""
|
|
191
|
+
try:
|
|
192
|
+
header = {
|
|
193
|
+
"Content-Type": "application/json"
|
|
194
|
+
}
|
|
195
|
+
response = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={self.key}", headers=header, data=json.dumps(data))
|
|
196
|
+
response_text = json.loads(response.text)
|
|
197
|
+
if str(response_text.get('errcode')) != '0':
|
|
198
|
+
raise Exception(response_text)
|
|
199
|
+
if response.status_code == 200:
|
|
200
|
+
result = json.loads(response.text)
|
|
201
|
+
return result
|
|
202
|
+
else:
|
|
203
|
+
print("HTTP Error:", response.status_code)
|
|
204
|
+
return None
|
|
205
|
+
except Exception as err:
|
|
206
|
+
raise Exception("Send Chat Message error", err)
|
|
207
|
+
|
|
208
|
+
def img_to_md5(self, img_path):
|
|
209
|
+
# 读取图片文件并计算MD5值
|
|
210
|
+
with open(img_path, 'rb') as image_file:
|
|
211
|
+
image_data = image_file.read()
|
|
212
|
+
return hashlib.md5(image_data).hexdigest()
|
|
213
|
+
|
|
214
|
+
def img_to_base64(self, img_path):
|
|
215
|
+
# 读取图片文件并转换为Base64编码
|
|
216
|
+
with open(img_path, 'rb') as image_file:
|
|
217
|
+
image_data = image_file.read()
|
|
218
|
+
return base64.b64encode(image_data).decode('utf-8')
|
|
219
|
+
|
|
220
|
+
# 通过企微应用发送消息
|
|
221
|
+
class WxWorkAppBot:
|
|
222
|
+
def __init__(self, corpid, corpsecret, agentid):
|
|
223
|
+
self.corpid = corpid
|
|
224
|
+
self.corpsecret = corpsecret
|
|
225
|
+
self.agentid = agentid
|
|
226
|
+
self.access_token = self._getToken()
|
|
227
|
+
|
|
228
|
+
def _getToken(self):
|
|
229
|
+
try:
|
|
230
|
+
if all([self.corpid, self.corpsecret]):
|
|
231
|
+
url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}".format(
|
|
232
|
+
corpid=self.corpid, corpsecret=self.corpsecret)
|
|
233
|
+
response = requests.get(url)
|
|
234
|
+
if response.status_code == 200:
|
|
235
|
+
result = json.loads(response.text)
|
|
236
|
+
return result['access_token']
|
|
237
|
+
else:
|
|
238
|
+
print("HTTP Error:", response.status_code)
|
|
239
|
+
return None
|
|
240
|
+
except Exception as err:
|
|
241
|
+
raise Exception("get WeChat access Token error", err)
|
|
242
|
+
|
|
243
|
+
def _send_msg(self, data):
|
|
244
|
+
self._check_token()
|
|
245
|
+
try:
|
|
246
|
+
send_url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}".format(
|
|
247
|
+
access_token=self.access_token)
|
|
248
|
+
response = requests.post(send_url, json.dumps(data))
|
|
249
|
+
if response.status_code == 200:
|
|
250
|
+
result = json.loads(response.text)
|
|
251
|
+
return result
|
|
252
|
+
else:
|
|
253
|
+
print("HTTP Error:", response.status_code)
|
|
254
|
+
return None
|
|
255
|
+
except Exception as err:
|
|
256
|
+
raise Exception("send WeChat Message error", err)
|
|
257
|
+
|
|
258
|
+
def _check_token(self):
|
|
259
|
+
if self.access_token is None:
|
|
260
|
+
self._getToken()
|
|
261
|
+
|
|
262
|
+
def send_msg(self, data):
|
|
263
|
+
return self._send_msg(data)
|
|
264
|
+
|
|
265
|
+
def upload_media(self, filetype, filepath, filename):
|
|
266
|
+
"""
|
|
267
|
+
上传临时素材到企微并获取media_id
|
|
268
|
+
:param filetype: 图片(image)、语音(voice)、视频(video),普通文件(file)
|
|
269
|
+
:param filepath:
|
|
270
|
+
:param filename:
|
|
271
|
+
:return: media_id
|
|
272
|
+
"""
|
|
273
|
+
try:
|
|
274
|
+
self._check_token()
|
|
275
|
+
post_file_url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={access_token}&type={filetype}".format(
|
|
276
|
+
filetype=filetype,
|
|
277
|
+
access_token=self.access_token)
|
|
278
|
+
|
|
279
|
+
m = MultipartEncoder(
|
|
280
|
+
fields={filename: (filename, open(filepath + filename, 'rb'), 'text/plain')},
|
|
281
|
+
)
|
|
282
|
+
response = requests.post(url=post_file_url, data=m, headers={'Content-Type': m.content_type})
|
|
283
|
+
if response.status_code == 200:
|
|
284
|
+
result = json.loads(response.text)
|
|
285
|
+
return result['media_id']
|
|
286
|
+
else:
|
|
287
|
+
print("HTTP Error:", response.status_code)
|
|
288
|
+
return None
|
|
289
|
+
except Exception as err:
|
|
290
|
+
raise Exception("upload media error", err)
|
|
291
|
+
|
|
292
|
+
def get_media(self, media_id):
|
|
293
|
+
"""
|
|
294
|
+
获取临时素材
|
|
295
|
+
:param media_id:
|
|
296
|
+
:return: 返回二进制形式
|
|
297
|
+
"""
|
|
298
|
+
try:
|
|
299
|
+
self._check_token()
|
|
300
|
+
url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"
|
|
301
|
+
params = {
|
|
302
|
+
"access_token": self.access_token,
|
|
303
|
+
"media_id" : media_id
|
|
304
|
+
}
|
|
305
|
+
response = requests.get(url=url, params=params)
|
|
306
|
+
if response.status_code == 200:
|
|
307
|
+
content_type = response.headers.get('Content-Type')
|
|
308
|
+
if content_type == 'application/json':
|
|
309
|
+
response_data = json.loads(response.text)
|
|
310
|
+
print("Error:", response_data.get("errmsg"))
|
|
311
|
+
return None
|
|
312
|
+
else:
|
|
313
|
+
return response.content
|
|
314
|
+
else:
|
|
315
|
+
print("HTTP Error:", response.status_code)
|
|
316
|
+
return None
|
|
317
|
+
except Exception as err:
|
|
318
|
+
raise Exception("get media error", err)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
qrpa/RateLimitedSender.py,sha256=K8DIzpn0_0JdV_xzU9XQ98hfSbYzGlh6aA1R23K6vMY,1376
|
|
2
|
+
qrpa/__init__.py,sha256=Cbp-_pDDYI-Fjpf-kSEa6PNpE4tj6MG6rUoiltkZWdI,1161
|
|
3
|
+
qrpa/db_migrator.py,sha256=Uen6KNCJCovbcaVIsD_wliF0gMKFpZAT7Zg9Qj2c-C8,21265
|
|
4
|
+
qrpa/feishu_bot_app.py,sha256=h7UbtsLkjMIB2XTVYhWEIvdYzPHdXT1DMd39yXuX-x0,21705
|
|
5
|
+
qrpa/feishu_client.py,sha256=gXvyhf7r-IqeDhPjM01SfsGf17t8g1ZwUAkhymBkBeg,17544
|
|
6
|
+
qrpa/feishu_logic.py,sha256=yuwb-LeZiHKGlz-W8JobinorHonVa8L-5h12WxnU7_Q,67508
|
|
7
|
+
qrpa/fun_base.py,sha256=HYxSinJciciwVSC9dE26nCc17qnbGhTddUdOacI8drQ,10607
|
|
8
|
+
qrpa/fun_excel.py,sha256=n6_akVfefYvRqVb8CoS8HtQ4YFmi33XE4wezQPRQbcw,137803
|
|
9
|
+
qrpa/fun_file.py,sha256=1PNYM71cVWWUjIgrutzw-5mKOGiBAeLrnkXcLMTIBhA,11648
|
|
10
|
+
qrpa/fun_web.py,sha256=0qmnAulHNR72-BGruQ-RQEVwsR60CkgnQMJIV6obUmU,21501
|
|
11
|
+
qrpa/fun_win.py,sha256=vMdVh00dsnVz8Wey4Bq7J3RPZAY8B_bI_IKphOX1cE8,7836
|
|
12
|
+
qrpa/shein_daily_report_model.py,sha256=O8s9qM45WZRoAgxUFRngvmBrc29v7Uf2ye7K8_bcSRg,12214
|
|
13
|
+
qrpa/shein_excel.py,sha256=VWJVqQ6yZ71zCKSBuJXrnEjtyydkDbtTl8SbfaeVXLs,194648
|
|
14
|
+
qrpa/shein_lib.py,sha256=mzmyxk_PiIJZmIR93WwUdrj8iGV8gDeZH5oIvtKeHoE,259253
|
|
15
|
+
qrpa/shein_mysql.py,sha256=2LFNBuGSH0VzsuZ717WH0Grt4rT1BnGhpp_UwSA0lxQ,5140
|
|
16
|
+
qrpa/shein_sqlite.py,sha256=i4xwNf60eoG6wbWM1R2i5pDdVW1ZMy6uy9nB-c2WKzk,5554
|
|
17
|
+
qrpa/shein_ziniao.py,sha256=N9_67JXxPBBY3q1-YoUnpGW91Q_Ty9FgOPT-AnW6iiw,22017
|
|
18
|
+
qrpa/temu_chrome.py,sha256=jAYv59Z1uoRSVim81EF2R2tEgQYYForiYhWOCKmy_mo,2747
|
|
19
|
+
qrpa/temu_excel.py,sha256=AqeMyJFjxf8slczbLzK4XKHdIiNZ8T-uDjB6DPj4DwU,6851
|
|
20
|
+
qrpa/temu_lib.py,sha256=myvlEAE5yNtgt1TUrx8fBRpvw883jpyePTPLd0_7tf4,7131
|
|
21
|
+
qrpa/time_utils.py,sha256=pHhADD-2WnzwWbEdnGh5_vR5TxmJycGex4zzI-5_fAQ,32340
|
|
22
|
+
qrpa/time_utils_example.py,sha256=80zzunKw7F1S8MOwNFmmiCnI8MOYoh4PH-25UrEGuF0,7810
|
|
23
|
+
qrpa/wxwork.py,sha256=Vy8PGEtlTWt4-1laVhuqpJUGCFH2JymgbjvH00aaBog,10946
|
|
24
|
+
qrpa/mysql_module/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
+
qrpa/mysql_module/new_product_analysis_model.py,sha256=H_RKZB-2wqWeDhnt_KEA8LVivAwK3XOqYLHIqUgcOZE,21556
|
|
26
|
+
qrpa/mysql_module/shein_ledger_model.py,sha256=KGKfGyzS00rbBZhiZhAzypwYPGs7OdfRLnH2ea36Vm8,18161
|
|
27
|
+
qrpa/mysql_module/shein_ledger_month_report_model.py,sha256=lONWxSza1507RFvy5hP1-6mjaNhuCoetPZzsqYd5B5Y,26596
|
|
28
|
+
qrpa/mysql_module/shein_product_model.py,sha256=jBxamujzYxrhxvZnH_kQW4O0QPzwTru_AqEMLDQtiMI,19582
|
|
29
|
+
qrpa/mysql_module/shein_return_order_model.py,sha256=FoxKJPIg2JRCrK-bblfjWgiuBAklarWNU5_4zAE3SIs,37430
|
|
30
|
+
qrpa/mysql_module/shein_store_model.py,sha256=iTO83PXZNnzaf3qqtIFMFmmQQL9C-pOazOJKXCatVUo,20537
|
|
31
|
+
qrpa/mysql_module/shein_supplier_info_model.py,sha256=dpGCNOi0pu0-p5weuj9gGkBBe5r68-2P-Jv3FNvZQvQ,29860
|
|
32
|
+
qrpa/mysql_module/shein_wallet_model.py,sha256=1v2OGl3n4IxcK1mhBQtb1xzQFlrby17pgob4LHtC5Ko,27662
|
|
33
|
+
qrpa-1.1.79.dist-info/METADATA,sha256=xBPNDnVjoCoimiEhy4yVZbiVEaE8uf9g6h68_C66OkU,231
|
|
34
|
+
qrpa-1.1.79.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
35
|
+
qrpa-1.1.79.dist-info/top_level.txt,sha256=F6T5igi0fhXDucPPUbmmSC0qFCDEsH5eVijfVF48OFU,5
|
|
36
|
+
qrpa-1.1.79.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
qrpa
|