From d5390da32f8e114fd1c6b86de64aedb7ad8d8765 Mon Sep 17 00:00:00 2001 From: psycodad Date: Mon, 22 Jun 2020 15:29:58 +0200 Subject: [PATCH] added checked_numbers.csv --- README.md | 11 ++++++++++- check_postcsv.py | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 627eea4..57daddc 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,13 @@ Example: ./check_postcsv.py /data/postarchiv/ -(/data/postarchiv/ being the folder where you store all your csv's from post) \ No newline at end of file +- /data/postarchiv/ being the folder where you store all your csv's downloaded from swisspost +- in above directory a file named 'checked_numbers.csv' is expected, with the following format: +,"" +,"" +i.e. +9960074598045013115,"Retoursendung" +This allows you to record the tracking numbers you have already checked on swisspost website, so you only have to check new ones marked with "CHECK-IT!". + + + diff --git a/check_postcsv.py b/check_postcsv.py index 8561009..11a9f2b 100755 --- a/check_postcsv.py +++ b/check_postcsv.py @@ -2,6 +2,9 @@ import csv, sys, os, glob +FNAME_CHECKED = 'checked_numbers.csv' + +checked_list = {} tr_list = [] dub_tr = [] dub_detected = 0 @@ -10,12 +13,21 @@ dub_detected = 0 dirname = sys.argv[1] print "Verwende Verzeichnis", dirname +# read checked tracking numbers +with open (os.path.join(dirname, FNAME_CHECKED)) as checked_obj: + d = csv.reader(checked_obj, delimiter=',', quoting=csv.QUOTE_ALL) + for r in d: + tr_id = int(r[0]) + reason = r[1] + checked_list[tr_id] = reason + + dirlist = os.listdir(dirname) for fname in dirlist: fbase, fext = os.path.splitext(fname) fullfname = os.path.join(dirname, fname) print fname, fbase, fext - if fext != ".csv": + if fext != ".csv" or fname == FNAME_CHECKED: print "Ueberspringe Datei", fname continue @@ -41,6 +53,9 @@ print "Dubletten erkannt:", dub_detected print "***********************" for dub in dub_tr: - #print dub - print dub[0], dub[4], dub[5], dub[6], dub[7], int(dub[8].replace("=", "").strip('"')) + tracking_nr = int(dub[8].replace("=", "").strip('"')) + if checked_list.has_key(tracking_nr): + print dub[0], dub[4], dub[5], dub[6], dub[7], int(dub[8].replace("=", "").strip('"')), checked_list[tracking_nr] + else: + print dub[0], dub[4], dub[5], dub[6], dub[7], int(dub[8].replace("=", "").strip('"')), "***** CHECK-IT! *****"