fix price comparision and latest column reordering
i.e. latest Deutsche Post update inserted some columns, thus using the headers is more robust.
This commit is contained in:
parent
2589eb30d2
commit
4e3818723c
|
@ -14,41 +14,46 @@
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import csv
|
import csv
|
||||||
|
import decimal
|
||||||
|
|
||||||
|
def quantize(x):
|
||||||
|
x = decimal.Decimal(x).quantize(decimal.Decimal('.01'))
|
||||||
|
|
||||||
def main(csv_filename, json_filename, filename):
|
def main(csv_filename, json_filename, filename):
|
||||||
with open(csv_filename, newline='', encoding='latin-1') as f \
|
with open(csv_filename, newline='', encoding='latin-1') as f \
|
||||||
, open(json_filename) as g \
|
, open(json_filename) as g \
|
||||||
, open(filename, 'w') as h:
|
, open(filename, 'w') as h:
|
||||||
rows = csv.reader(f, delimiter=';')
|
rows = csv.DictReader(f, delimiter=';')
|
||||||
products = json.load(g)
|
products = json.load(g)
|
||||||
|
|
||||||
seen_ids = set()
|
seen_ids = set()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
key, price = row[2], row[5].replace(',', '.')
|
key, price = row['PROD_ID'], row['PROD_BRPREIS'].replace(',', '.')
|
||||||
inter, weight, name = row[3]=='1', row[21], row[4]
|
inter, weight, name = (row['PROD_AUSR'] in ('1', 'I')), row['MAXG'], row['PROD_NAME']
|
||||||
seen_ids.add(row[2])
|
seen_ids.add(key)
|
||||||
if key in products:
|
if key in products:
|
||||||
p = products[key]
|
p = products[key]
|
||||||
oprice, ointer = p['cost_price'], p['international']
|
oprice, ointer = p['cost_price'], p['international']
|
||||||
oweight, oname = p['max_weight'], p['name']
|
oweight, oname = p['max_weight'], p['name']
|
||||||
# row[5] vs. row[7] => total vs. base product price
|
# row[5] vs. row[7] => total vs. base product price
|
||||||
# row[4] vs. row[6] => complete vs. base product name
|
# row[4] vs. row[6] => complete vs. base product name
|
||||||
|
price, oprice = quantize(price), quantize(oprice)
|
||||||
c = False
|
c = False
|
||||||
if price != oprice:
|
if price != oprice:
|
||||||
print(f'Price of {name} ({key}) changed: {oprice} -> {price} (from {row[0]})')
|
print(f'Price of {name} ({key}) changed: {oprice} -> {price} (from {row["PROD_GUEAB"]})')
|
||||||
c = True
|
c = True
|
||||||
p['cost_price'] = price
|
p['cost_price'] = price
|
||||||
if inter != ointer:
|
if inter != ointer:
|
||||||
print(f'Nationality of {name} ({key}) changed: {ointer} -> {inter} (from {row[0]})')
|
print(f'Nationality of {name} ({key}) changed: {ointer} -> {inter} (from {row["PROD_GUEAB"]})')
|
||||||
c = True
|
c = True
|
||||||
p['international'] = inter
|
p['international'] = inter
|
||||||
if weight != oweight:
|
if weight != oweight:
|
||||||
print(f'Weight of {name} ({key}) changed: {oweight} -> {weight} (from {row[0]})')
|
print(f'Weight of {name} ({key}) changed: {oweight} -> {weight} (from {row["PROD_GUEAB"]})')
|
||||||
c = True
|
c = True
|
||||||
p['max_weight'] = weight
|
p['max_weight'] = weight
|
||||||
# The names returned by the ProdWS differ from the ones included in the PPL ...
|
# The names returned by the ProdWS differ from the ones included in the PPL ...
|
||||||
# if name != oname:
|
# if name != oname:
|
||||||
# print(f'Name of {name} ({key}) changed: {oname} -> {name} (from {row[0]})')
|
# print(f'Name of {name} ({key}) changed: {oname} -> {name} (from {row["PROD_GUEAB"]})')
|
||||||
# c = True
|
# c = True
|
||||||
if c:
|
if c:
|
||||||
print('*'*75)
|
print('*'*75)
|
||||||
|
|
Loading…
Reference in New Issue