qrpa 1.1.33__py3-none-any.whl → 1.1.35__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_mysql.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import json
2
2
 
3
+ from . import TimeUtils
3
4
  from .mysql_module.shein_return_order_model import SheinReturnOrderManager
4
5
  from .mysql_module.shein_product_model import SheinProductManager
5
6
  from .mysql_module.shein_ledger_model import SheinLedgerManager
7
+ from .mysql_module.new_product_analysis_model import NewProductAnalysisManager
6
8
  from .fun_base import log
7
9
 
8
10
  import os
@@ -68,3 +70,23 @@ class SheinMysql:
68
70
  manager.upsert_product_detail(spu, 'attribute_template', data_list)
69
71
  else:
70
72
  log(f'文件不存在: {attribute_file}')
73
+
74
+ def upsert_shein_new_product_analysis(self, stat_date):
75
+ log(f'当前使用的数据库: {self.config.db.database_url}')
76
+ # 创建管理器实例
77
+ manager = NewProductAnalysisManager(self.config.db.database_url)
78
+ # 创建数据表
79
+ manager.create_table()
80
+ src_directory = f'{self.config.auto_dir}/shein/product_analysis'
81
+ for file in os.listdir(src_directory):
82
+ # 检查是否为文件且符合命名模式
83
+ if file.startswith(f"skc_model_") and file.endswith(f"_{stat_date}.json"):
84
+ file_path = os.path.join(src_directory, file)
85
+ filename = os.path.basename(file_path) # 获取 "tool.py"
86
+ name = os.path.splitext(filename)[0]
87
+ store_username = name.split('_')[2]
88
+ # 读取JSON文件
89
+ with open(file_path, 'r', encoding='utf-8') as f:
90
+ json_data = json.load(f)
91
+ count = manager.import_from_json(json_data)
92
+ print(f"成功导入 {store_username} {count} 条记录")
qrpa/shein_sqlite.py CHANGED
@@ -1,154 +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__':
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
154
  main(sys.argv)