Skip to content

Commit

Permalink
change format to size duplicated and add formats
Browse files Browse the repository at this point in the history
  • Loading branch information
argorar committed Jun 13, 2023
1 parent f3c123c commit 40180de
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions walk3r.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logging.basicConfig(level=logging.DEBUG, filename='logs.log',
format='%(asctime)s :: %(message)s',
filemode='w')
current_version = "1.1.0"
current_version = "1.1.1"

class Counter(dict):
def __missing__(self, key):
Expand Down Expand Up @@ -75,15 +75,20 @@ def argument():
scan(directory)
except:
print(f'{bcolors.WARNING} Please pass directory {bcolors.ENDC}')


def truncate(number: float, max_decimals: int) -> float:
int_part, dec_part = str(number).split(".")
return float(".".join((int_part, dec_part[:max_decimals])))

def show_file_formats():
print(f'\nTotal files duplicated: {duplicates}\n')
print(f'\nTotal files size: {files_size/1024}KB\n')
print(f'\nTotal files size: {truncate((files_size/1024)/1024, 2)} MB\n')
print('\nTotal files by format:\n')
print ("{:<8} {:<10}".format('Format','Cuantity'))
for key, value in extensions.items():
print ("{:<8} {:<10}".format(key, value))


def scan(directory):
global duplicates
global files_size
Expand All @@ -93,7 +98,7 @@ def scan(directory):
file_path = os.path.join(directory_name, file_mame)
extension = os.path.splitext(file_mame)[1].replace('.', '')
extensions[extension] += 1
if extension == 'png' or extension == 'jpg' or extension == 'JPG' or extension == 'mp4':
if extension == 'png' or extension == 'jpg' or extension == 'JPG' or extension == 'mp4' or extension == 'mov' or extension == 'webm':
with open(file_path, "rb") as f:
file_hash = hashlib.blake2b()
while chunk := f.read(8192):
Expand Down

0 comments on commit 40180de

Please sign in to comment.