2929debug = config .get ('debug' , False )
3030known_printers = config .get ('knownprinters' , [])
3131snmpv1_community = config ['snmpv1_community' ]
32- bash_commands = config ['bashCommands' ]
3332###############################################
3433
35- # Function to execute a given bash command
36- def execute_command (command_name ):
37- command = bash_commands .get (command_name )
38- if command :
39- result = subprocess .run (command , shell = True , capture_output = True , text = True )
40- print (f"Output for { command_name } :\n { result .stdout } " )
41- print (f"Error for { command_name } :\n { result .stderr } " )
42- else :
43- print (f"Command { command_name } not found in the configuration." )
44-
45- execute_command ('StartBashCounter' )
4634
4735# Get the base date
4836base_date = datetime .now ()
4937if config .get ('debug_date' , False ):
5038 base_date = datetime .strptime (f"01-{ config .get ('debug_MM_YYYY' , required = False )} " , "%d-%m-%Y" )
5139
52- # Calculate the adjusted date based on offset
53- date_filename_offset = - config .get ('DateFilenameOffset' , 0 )
54- adjusted_date = base_date + timedelta (days = date_filename_offset )
55- adjusted_year = adjusted_date .strftime ("%Y" )
40+ # Calculate the adjusted date based on offset
41+ adjusted_year = base_date .strftime ("%Y" )
5642
5743# Create a subdirectory for the year
5844year_output_dir = os .path .join (output_directory , adjusted_year )
5945os .makedirs (year_output_dir , exist_ok = True )
6046
6147
6248# Define the filename with the requested naming scheme
63- filename = f"totals_{ adjusted_date :%Y_%m} .csv"
49+ filename = f"totals_{ base_date :%Y_%m} .csv"
6450csvfile_path = os .path .join (year_output_dir , filename )
6551logfile = os .path .join (year_output_dir , "TodaysLog_PrinterCounter.txt" )
6652
@@ -151,7 +137,7 @@ def try_snmp_get(ip, oids):
151137current_month = datetime .now ().month
152138
153139# Format the expected file name
154- foundPrintersCSV = f"foundprinters_{ adjusted_date :%Y-%m} .csv"
140+ foundPrintersCSV = f"foundprinters_{ base_date :%Y-%m} .csv"
155141foundprinters_dir = os .path .normpath (os .path .join (script_dir , f"../{ output_name } " ))
156142echo = f"searching: { foundprinters_dir } "
157143expected_file_path = os .path .join (year_output_dir , foundPrintersCSV )
@@ -287,5 +273,4 @@ def try_snmp_get(ip, oids):
287273timeend = datetime .now ()
288274elapsed_time = timeend - timestart
289275formatted_elapsed_time = format_elapsed_time (elapsed_time , format_type = 1 )
290- print (f"All done in { elapsed_time } seconds" )
291- execute_command ('EndBashCounter' )
276+ print (f"All done in { elapsed_time } seconds" )
0 commit comments