qrpa 1.0.16__py3-none-any.whl → 1.0.18__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/shein_sqlite.py ADDED
@@ -0,0 +1,154 @@
1
+ from .fun_base import log
2
+
3
+ import sqlite3
4
+ from datetime import datetime, timedelta
5
+ import os
6
+ import sys
7
+
8
+
9
+ auto_dir = 'D:/auto'
10
+ db_file = f'{auto_dir}/shein/db/shein_sku_sales.db'
11
+
12
+ # log(db_file)
13
+
14
+
15
+ def main(args):
16
+ init_db()
17
+ # exists_sales_1_days_ago('653231597')
18
+ # log(get_last_week_sales('6960380466'))
19
+ # log(get_sales('6960380466', '2025-02-25', '2025-03-04'))
20
+ # log(get_near_week_sales('I46mraado10r'))
21
+ # log(get_last_week_sales('I46mraado10r','2025-03-08','2025-03-14'))
22
+ # create_indexes()
23
+
24
+ def init_db():
25
+ # 获取文件夹路径
26
+ folder_path = os.path.dirname(db_file)
27
+ # 如果文件夹不存在,则创建
28
+ if not os.path.exists(folder_path):
29
+ os.makedirs(folder_path)
30
+ log(f"文件夹已创建: {folder_path}")
31
+ conn = sqlite3.connect(db_file)
32
+ cursor = conn.cursor()
33
+ cursor.execute('''
34
+ CREATE TABLE IF NOT EXISTS sales (
35
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
36
+ skc TEXT,
37
+ date TEXT,
38
+ skc_sale INTEGER,
39
+ skc_order INTEGER,
40
+ sku TEXT,
41
+ attr_name TEXT,
42
+ sku_sale INTEGER,
43
+ sku_order INTEGER
44
+ )
45
+ ''')
46
+ conn.commit()
47
+ conn.close()
48
+ log('新建数据库成功', db_file)
49
+
50
+ init_db()
51
+
52
+ def insert_sales(skc, date, skc_sale, skc_order, sku, attr_name, sku_sale, sku_order):
53
+ conn = sqlite3.connect(db_file)
54
+ cursor = conn.cursor()
55
+ cursor.execute('''
56
+ SELECT 1 FROM sales WHERE sku = ? AND date = ?
57
+ ''', (sku, date))
58
+
59
+ if cursor.fetchone() is None:
60
+ cursor.execute('''
61
+ INSERT INTO sales (skc, date, skc_sale, skc_order, sku, attr_name, sku_sale, sku_order)
62
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
63
+ ''', (skc, date, skc_sale, skc_order, sku, attr_name, sku_sale, sku_order))
64
+ conn.commit()
65
+
66
+ conn.close()
67
+
68
+ def get_sales(sku, start_date, end_date):
69
+ conn = sqlite3.connect(db_file)
70
+ cursor = conn.cursor()
71
+ cursor.execute('''
72
+ SELECT SUM(sku_sale), SUM(sku_order) FROM sales WHERE sku = ? AND date BETWEEN ? AND ?
73
+ ''', (sku, start_date, end_date))
74
+
75
+ result = cursor.fetchone() # 获取查询结果
76
+ sales_num = result[0] if result[0] is not None else 0
77
+ orders_num = result[1] if result[1] is not None else 0
78
+
79
+ conn.close()
80
+
81
+ log('get_sales:', sku, start_date, end_date, sales_num, orders_num)
82
+ return sales_num, orders_num # 返回销售量和订单量的元组
83
+
84
+ def get_last_week_sales(sku):
85
+ today = datetime.today().date()
86
+ # last_week_start = today - timedelta(days=today.weekday() + 14)
87
+ last_week_start = (datetime.now() - timedelta(days=14)).strftime("%Y-%m-%d")
88
+ last_week_end = (datetime.now() - timedelta(days=8)).strftime("%Y-%m-%d")
89
+ # log('远7天',last_week_start,last_week_end,sku)
90
+ return get_sales(sku, str(last_week_start), str(last_week_end))
91
+
92
+ def get_near_week_sales(sku):
93
+ today = datetime.today().date()
94
+ # last_week_start = today - timedelta(days=today.weekday() + 14)
95
+ last_week_start = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d")
96
+ last_week_end = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
97
+ # log('远7天',last_week_start,last_week_end,sku)
98
+ return get_sales(sku, str(last_week_start), str(last_week_end))
99
+
100
+ def get_last_month_sales(sku):
101
+ today = datetime.today().date()
102
+ # first_day_of_this_month = today.replace(day=1)
103
+ # last_month_end = first_day_of_this_month - timedelta(days=1)
104
+ # last_month_start = last_month_end.replace(day=1)
105
+ last_month_start = (datetime.now() - timedelta(days=60)).strftime("%Y-%m-%d")
106
+ last_month_end = (datetime.now() - timedelta(days=31)).strftime("%Y-%m-%d")
107
+ # log('远30天',last_month_start,last_month_end,sku)
108
+ return get_sales(sku, str(last_month_start), str(last_month_end))
109
+
110
+ def get_near_month_sales(sku):
111
+ today = datetime.today().date()
112
+ # first_day_of_this_month = today.replace(day=1)
113
+ # last_month_end = first_day_of_this_month - timedelta(days=1)
114
+ # last_month_start = last_month_end.replace(day=1)
115
+ last_month_start = (datetime.now() - timedelta(days=30)).strftime("%Y-%m-%d")
116
+ last_month_end = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
117
+ # log('远30天',last_month_start,last_month_end,sku)
118
+ return get_sales(sku, str(last_month_start), str(last_month_end))
119
+
120
+ def exists_sales_1_days_ago(skc):
121
+ conn = sqlite3.connect(db_file) # 替换成你的数据库文件
122
+ cursor = conn.cursor()
123
+ date_threshold = (datetime.today().date() - timedelta(days=1)).isoformat()
124
+ # 使用 str.format() 格式化 SQL
125
+ sql = '''
126
+ SELECT 1 FROM sales WHERE skc = '{skc}' AND date = '{date}' LIMIT 1
127
+ '''.format(skc=skc, date=date_threshold)
128
+ log("exists_sales_1_days_ago:", sql.strip()) # 打印 SQL 语句
129
+ cursor.execute('''
130
+ SELECT 1 FROM sales WHERE skc = ? AND date <= ? LIMIT 1
131
+ ''', (skc, date_threshold))
132
+ result = cursor.fetchone()
133
+ conn.close()
134
+ return result is not None
135
+
136
+ def create_indexes():
137
+ conn = sqlite3.connect(db_file)
138
+ cursor = conn.cursor()
139
+ # 创建 spu + date 联合索引
140
+ cursor.execute('''
141
+ CREATE INDEX IF NOT EXISTS idx_sales_skc_date ON sales (skc, date);
142
+ ''')
143
+ # 创建 sku + date 唯一索引
144
+ cursor.execute('''
145
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_sales_sku_date_unique ON sales (sku, date);
146
+ ''')
147
+ conn.commit() # 提交更改
148
+ conn.close() # 关闭连接
149
+ log("索引创建成功!")
150
+
151
+ init_db()
152
+
153
+ if __name__ == '__main__':
154
+ main(sys.argv)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qrpa
3
- Version: 1.0.16
3
+ Version: 1.0.18
4
4
  Summary: qsir's rpa library
5
5
  Author: QSir
6
6
  Author-email: QSir <1171725650@qq.com>
@@ -1,18 +1,19 @@
1
1
  qrpa/RateLimitedSender.py,sha256=hqvb1qspDFaW4RsLuVufylOrefkMgixANKeBaGEqYb4,1421
2
- qrpa/__init__.py,sha256=0EV-ZBTPzRP4rjVqFU2FYe1gxrtzdomd84a3dzNGLpM,761
2
+ qrpa/__init__.py,sha256=EysO3QHdHWPWuVmtbekAZBSKSlCIAHnLzg2O6e26nNs,801
3
3
  qrpa/db_migrator.py,sha256=2VmhzcMsU0MKpl-mNCwKyV8tLTqyEysSpP27-S_rQZ8,21862
4
4
  qrpa/fun_base.py,sha256=W_owEa8-yuGG18n9kX3remm9YTzym69ztQjtYCNMTw4,3308
5
- qrpa/fun_excel.py,sha256=S-A-kTZ2e3dJ8NqdhiOFqTlcr0d6XLMP6imagztRel0,103605
5
+ qrpa/fun_excel.py,sha256=uaSNvJGA0vopBn0N__tVYpdeX4WlliOAQWP4sHanFUw,104030
6
6
  qrpa/fun_file.py,sha256=yzjDV16WL5vRys7J4uQcNzIFkX4D5MAlSCwxcD-mwQo,11966
7
7
  qrpa/fun_web.py,sha256=5QLQorAhRzMOGMRh4eCJ2UH8ZhVHvxkHwobWhmgU5qM,6286
8
8
  qrpa/fun_win.py,sha256=-LnTeocdTt72NVH6VgLdpAT9_C5oV9okeudXG6CftMA,8034
9
- qrpa/shein_excel.py,sha256=zP_WRZigbbDXXSeNei1j0sKO_-_gMBTd6wz05TwDfM0,7429
10
- qrpa/shein_lib.py,sha256=xOyXgyS1a6GMjho5RFrfPo0kp56Hjj0IquIuF64-1jo,52689
9
+ qrpa/shein_excel.py,sha256=7YE-qlTfLTuVPTAnLKfXoWbO_Jz4O1RJnTZac_p7EfM,13473
10
+ qrpa/shein_lib.py,sha256=VOKtgUK-2stWLwASjQRfiYHkVG7M2Tzk0VV-XNyXkes,65915
11
+ qrpa/shein_sqlite.py,sha256=ZQwD0Gz81q9WY7tY2HMEYvSF9r3N_G_Aur3bYfST9WY,5707
11
12
  qrpa/shein_ziniao.py,sha256=nSqqcEPh4nVQtUxUnIRzeZfTLyXywGPjPZn5pP-w57U,18309
12
13
  qrpa/time_utils.py,sha256=ef0hhbN_6b-gcnz5ETIVOoxemIMvcxGVGGIRnHnGaBo,29564
13
14
  qrpa/time_utils_example.py,sha256=shHOXKKF3QSzb0SHsNc34M61wEkkLuM30U9X1THKNS8,8053
14
15
  qrpa/wxwork.py,sha256=8LzRmoHYo0KBfZ1cmkWPj824Zp52NAUYm3RXYzmIIi0,10507
15
- qrpa-1.0.16.dist-info/METADATA,sha256=Z7iNE0BPDJucPDz6Gg8ptn1ZHTil51WyTeylRcdud94,231
16
- qrpa-1.0.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- qrpa-1.0.16.dist-info/top_level.txt,sha256=F6T5igi0fhXDucPPUbmmSC0qFCDEsH5eVijfVF48OFU,5
18
- qrpa-1.0.16.dist-info/RECORD,,
16
+ qrpa-1.0.18.dist-info/METADATA,sha256=0hxXj_cyeUQ0fLSW8-OZYr_lyqbPbRAFiGHQ__o5KqA,231
17
+ qrpa-1.0.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ qrpa-1.0.18.dist-info/top_level.txt,sha256=F6T5igi0fhXDucPPUbmmSC0qFCDEsH5eVijfVF48OFU,5
19
+ qrpa-1.0.18.dist-info/RECORD,,
File without changes