-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_name_generator.py
More file actions
28 lines (24 loc) · 1007 Bytes
/
file_name_generator.py
File metadata and controls
28 lines (24 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python3
import argparse
import sys
"""
Implementing the parser for named args
"""
parser=argparse.ArgumentParser(
prog="File Name Generator",
description="This is help to create file name from given text and remove all the unwanted, unsupported characters from the file name"
)
parser.add_argument("name", help="The string for the file name. The output string will strip all the unsuppored characters from the string")
parser.add_argument("--extention", "-e", help="The type of the file. Eg: pdf, jpg, etc.")
args = parser.parse_args()
"""
Function to generate a valid file name from entered string:wq
"""
if args.name:
input_text = args.name
unwanted_symbols = "!@#$%^&*(),.:;'|`'~-+=/><?\\\n\t "
output_text = "".join("_" if char in unwanted_symbols else char for char in input_text )
output_text += f".{args.extention}" if args.extention else ''
print(f"Generated file name: {output_text}")
else:
print(f"Name is not provided. Please provide the name")