-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestStockList.py
49 lines (37 loc) · 1.29 KB
/
TestStockList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from stockList import stockList
from common import common
import constants
import os
from sql import sql
def updateStockList():
s = stockList()
s.method()
filePath = sorted(os.listdir(constants.stockListPath), reverse=True)
c = common()
stockDict = c.readCSV(constants.stockListPath + filePath[0])
insert = []
update = []
if len(filePath) == 1:
for key in stockDict.keys():
insert.append([key, stockDict[key]])
else:
stockDictOld = c.readCSV(constants.stockListPath + filePath[1])
for key in stockDict.keys() - stockDictOld.keys():
insert.append([key, stockDict[key]])
#修改名称
for key in stockDict.keys() & stockDictOld.keys():
if stockDict[key] != stockDictOld[key]:
update.append([stockDict[key], key])
return insert, update
def saveStockList(insert, update):
s = sql()
insert_head_sql = constants.insert_head_sql
s.operation(insert_head_sql, insert)
update_head_sql = constants.update_head_sql
s.operation(update_head_sql, update)
if '__name__==__main__':
insert, update = updateStockList()
print(insert)
print(update)
#涉及数据库插入,所以最好待数据获取稳定时取消注释
# saveStockList(insert, update)