Commit 9f693399 by larosa

add script

parent 3d0f35b4
Showing with 21 additions and 6 deletions
import csv
import json
import logging
import time
logging.basicConfig(level=logging.INFO, filename='waldom_dollar.log', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('waldom_data_process_USD.py')
......@@ -30,8 +30,6 @@ class HandleCSV:
first_line = []
reader = csv.reader(f)
for index, row in enumerate(reader):
if index > 100:
break
if index == 0:
first_line = row
flag = self.validate(first_line)
......@@ -40,6 +38,7 @@ class HandleCSV:
return []
else:
json_str = self.generate_json(row, first_line)
print(json_str)
result.append(json_str)
logger.info("文件 %s 已解析" % path)
return result
......@@ -59,6 +58,7 @@ class HandleCSV:
table['ladder_price'] = []
table['supplier_name'] = 'Waldom美金'
table['goods_sn'] = ''
batch_sn_map = dict()
for i in range(len(title)):
ladder_item_map = dict()
if title[i] in title_map:
......@@ -86,13 +86,28 @@ class HandleCSV:
ladder_item_map['price_cn'] = float(0)
table['ladder_price'].append(ladder_item_map)
elif title[i] == 'Date Code':
items = str(arr[i]).split(sep=";")
print(items)
items_arr = str(arr[i]).split(sep=";")
for j in range(len(items_arr)):
item = items_arr[j]
split_item_arr = item.split(sep="|")
if len(split_item_arr) == 3:
number = split_item_arr[0].strip()
year = split_item_arr[1].strip()
if len(number) > 0 and len(year) >= 4 and number.isdigit() and str(year[len(year)-4:]).isdigit():
key = str(year[len(year)-2:]) + "+"
value = number
if key in batch_sn_map:
batch_sn_map[key] += int(value)
else:
batch_sn_map[key] = int(value)
table['batch_sn'] = batch_sn_map
return json.dumps(table, ensure_ascii=False)
if __name__ == '__main__':
start = time.time()
result = HandleCSV().parse('Tianyang_InventoryFeed.csv')
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