From 7ecc07780d3f2831231be7b45d1cb9f797dd98be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1=C4=8Dek?= Date: Thu, 14 Apr 2022 14:29:35 +0200 Subject: [PATCH] we are handling the dates without user input --- ucetnictvi_tm.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ucetnictvi_tm.py b/ucetnictvi_tm.py index fb0224e..0f88acb 100644 --- a/ucetnictvi_tm.py +++ b/ucetnictvi_tm.py @@ -21,9 +21,13 @@ FILE = FILE[0] ext_date_from_filaname = FILE.split('_')[-1] print(ext_date_from_filaname) -usrmonth = input("Month to be processed: ") -usrmonth = int(usrmonth) +# get month to be processed + +head, mid, tail = ext_date_from_filaname.partition('.') +print(head) +usrmonth = head[-2:] +print(usrmonth) dictionary = {} @@ -64,9 +68,17 @@ with open(FILE, newline='', encoding="utf-8") as csvfile: continue my_string = row['Začátek fakturačního období'] + #my_string = '2021-09-06' print("start date: ",my_string) + monthfromfile = my_string.split(".", 3) + print(monthfromfile[1]) + monthfromfile = monthfromfile[1] + + + + try: my_date = datetime.strptime(my_string, "%d.%m.%Y") except: @@ -78,8 +90,9 @@ with open(FILE, newline='', encoding="utf-8") as csvfile: #print(my_date.month) - if usrmonth != my_date.month: + if usrmonth != monthfromfile: print("skipping bad date") + continue #skip bad dates @@ -193,7 +206,7 @@ with open('output_TMCZ_'+ext_date_from_filaname, 'w') as f: f.close() - +sys.exit() with open('output_TMCZ_'+ext_date_from_filaname, "rb") as f: webhook.add_file(file=f.read(), filename='output_TMCZ_'+ext_date_from_filaname)