Commit b2056aa8 by larosa

resolve

parent d7fd8c93
Showing with 47 additions and 10 deletions
import csv import csv
import json import json
import logging import logging
import time
import openpyxl
import pandas as pd import pandas as pd
...@@ -21,22 +24,49 @@ title_arr = [ ...@@ -21,22 +24,49 @@ title_arr = [
'Price Break Qty 3', 'Price Break 3', 'Price Break Qty 4', 'Price Break 4', 'Price Break Qty 3', 'Price Break 3', 'Price Break Qty 4', 'Price Break 4',
'Price Break Qty 5', 'Price Break 5', 'Price Break Qty 6', 'Price Break 6', 'Price Break Qty 5', 'Price Break 5', 'Price Break Qty 6', 'Price Break 6',
'Price Break Qty 7', 'Price Break 7', 'Price Break Qty 8', 'Price Break 8', 'Price Break Qty 7', 'Price Break 7', 'Price Break Qty 8', 'Price Break 8',
'Price Break Qty 9', 'Price Break 9' 'Price Break Qty 9', 'Price Break 9', 'Date Code'
] ]
ladder_map = {
'Price Break Qty 1': 'Price Break 1',
'Price Break Qty 2': 'Price Break 2',
'Price Break Qty 3': '',
'Price Break Qty 4',
'Price Break Qty 5', 'Price Break Qty 6', 'Price Break Qty 7', 'Price Break Qty 8',
'Price Break Qty 9',
}
class HandleCSV: class HandleCSV:
def parse(self, path): def parse(self, path):
df = pd.read_excel(path, nrows=0) df = pd.read_excel(path, sheet_name=0)
first_row = [] if not self.validate(df.columns.values):
for i in range(len(df.columns)):
print(df.columns[i])
first_row.append(df.columns[i])
if not self.validate(first_row):
logger.error("文件 %s 格式错误" % path) logger.error("文件 %s 格式错误" % path)
return [] return []
data = pd.read_excel(path, title_arr) for i in range(len(df.index.values)):
print(data.values()) # print(df.loc[i, title_arr[0]])
table = dict()
for j in range(len(title_arr)):
ladder_item_map = dict()
data = df.loc[i, title_arr[j]]
if title_arr[j] == 'Manufacturer Name':
table['brand_name'] = data
elif title_arr[j] == 'Part Number':
table['goods_name'] = data
elif title_arr[j] == 'Stock EMEA' or \
title_arr[j] == 'Stock USA' or \
title_arr[j] == 'Stock APAC' or \
title_arr[j] == 'Stock CN':
if len(str(data).strip()) > 0:
if 'stock' in table:
table['stock'] += int(data)
else:
table['stock'] = int(data)
elif title_arr[j] == 'MOQ':
table['moq'] = data
elif title_arr[j] in ladder_map:
ladder_item_map['purchases'] = int(data)
ladder_item_map['price_us'] = float(0)
ladder_item_map['price_cn'] = float()
...@@ -49,9 +79,16 @@ class HandleCSV: ...@@ -49,9 +79,16 @@ class HandleCSV:
count += 1 count += 1
return count == size return count == size
def generate_json(self, ):
pass
if __name__ == '__main__': if __name__ == '__main__':
start = time.time()
HandleCSV().parse('Tianyang_Inventory_Feed_RMB.xlsx') HandleCSV().parse('Tianyang_Inventory_Feed_RMB.xlsx')
end = time.time()
print("spend time: " + str(end - start))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment