11""" Core redactor engine class implementation """
22
3+ from pyredactkit .common_jobs import CommonJobs
34import mimetypes
45import os
56import sys
1011
1112from pyredactkit .identifiers import Identifier
1213id_object = Identifier ()
14+ cj_object = CommonJobs ()
1315""" Coreredactor library """
1416
1517
@@ -158,7 +160,7 @@ def process_text(self, text=str, savedir="./"):
158160 kv_pairs = data [1 ]
159161 hash_map .update (kv_pairs )
160162 result .write (f"{ redacted_line } \n " )
161- self .write_hashmap (hash_map , generated_file , savedir )
163+ cj_object .write_hashmap (hash_map , generated_file , savedir )
162164 print (
163165 f"[+] .hashshadow_{ os .path .basename (generated_file )} .json file generated. Keep this safe if you need to undo the redaction." )
164166 print (
@@ -218,7 +220,7 @@ def process_custom_file(self, file_name, customfile=str, make_dir="./"):
218220 kv_pairs = data [1 ]
219221 secret_map .update (kv_pairs )
220222 result .write (redacted_line )
221- self .write_hashmap (secret_map , file_name , make_dir )
223+ cj_object .write_hashmap (secret_map , file_name , make_dir )
222224 print (
223225 f"[+] .hashshadow_{ os .path .basename (file_name )} .json file generated. Keep this safe if you need to undo the redaction." )
224226 print (f"[+] Redacted { redact_count } targets..." )
@@ -282,7 +284,7 @@ def process_core_file(self, filename, savedir="./"):
282284 kv_pairs = data [1 ]
283285 hash_map .update (kv_pairs )
284286 result .write (redacted_line )
285- self .write_hashmap (hash_map , filename , savedir )
287+ cj_object .write_hashmap (hash_map , filename , savedir )
286288 print (
287289 f"[+] .hashshadow_{ os .path .basename (filename )} .json file generated. Keep this safe if you need to undo the redaction." )
288290 print (f"[+] Redacted { count } targets..." )
@@ -293,65 +295,3 @@ def process_core_file(self, filename, savedir="./"):
293295 os .remove (f"{ savedir } redacted_{ os .path .basename (filename )} " )
294296 print ("[-] Removed incomplete redact file" )
295297 sys .exit ("[-] Unable to read file" )
296-
297- def process_report (self , filename , savedir = "./" ):
298- """Function to process calculate and generate report of man hour saved.
299- Args:
300- filename (str): File to count the words
301-
302- Returns:
303- Creates a report on estimated man hours/minutes saved.
304- """
305- try :
306- # Open a file read pointer as target_file
307- with open (filename , encoding = "utf-8" ) as target_file :
308- if savedir != "./" and savedir [- 1 ] != "/" :
309- savedir = savedir + "/"
310-
311- # created the directory if not present
312- if not os .path .exists (os .path .dirname (savedir )):
313- print (
314- "[+] "
315- + os .path .dirname (savedir )
316- + f"{ self .dir_create } "
317- )
318- os .makedirs (os .path .dirname (savedir ))
319-
320- text_chunk = target_file .read ()
321-
322- # Words per minute
323- WPM = 75
324-
325- word_length = 5
326- total_words = 0
327- for current_text in text_chunk :
328- total_words += len (current_text )/ word_length
329-
330- total_words = math .ceil (total_words )
331-
332- # Divide total words by words per minute read to get minutes and hour estimate.
333- reading_minutes = math .ceil (total_words / WPM )
334- reading_hours = math .floor (reading_minutes / 60 )
335-
336- word_report = f"[+] Estimated total words : { total_words } "
337- minutes_saved = f"[+] Estimated total minutes saved : { reading_minutes } "
338- man_hours_saved = f"[+] Estimated total man hours saved : { reading_hours } "
339-
340- print (word_report )
341- print (minutes_saved )
342- print (man_hours_saved )
343- # Open a file write pointer as result
344- # with open(
345- # f"{savedir}manhours_saved_{os.path.basename(filename)}",
346- # "w",
347- # encoding="utf-8",
348- # ) as result:
349- # result.write(word_report + "\n" +
350- # minutes_saved + "\n" + man_hours_saved)
351- # print(
352- # f"[+] Estimated man hours saved report saved to {savedir}manhours_saved_{os.path.basename(filename)}")
353-
354- except UnicodeDecodeError :
355- os .remove (f"manhour_saved_report_{ os .path .basename (filename )} " )
356- print ("[-] Removed incomplete report" )
357- sys .exit ("[-] Unable to read target file" )
0 commit comments