-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
39 lines (35 loc) · 1.5 KB
/
Copy pathconfig.py
File metadata and controls
39 lines (35 loc) · 1.5 KB
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
29
30
31
32
33
34
35
36
37
38
39
import pathlib
import tomli
import tomli_w
# === File Handling ===
# Gets the settings.toml data, creating it from the template on first run
def get_toml_data():
path = pathlib.Path(__file__).parent / "settings.toml"
if not path.exists():
template = pathlib.Path(__file__).parent / "settings.example.toml"
path.write_bytes(template.read_bytes())
settings_file = path.open(mode="rb")
settings_toml = tomli.load(settings_file)
settings_file.close()
return settings_toml
# Checks if the important values are empty
def is_toml_empty():
settings_toml = get_toml_data()
if str(settings_toml["smtp"]["username"]).strip() == "": return True
if str(settings_toml["smtp"]["passkey"]).strip() == "": return True
if str(settings_toml["smtp"]["smtp_server"]).strip() == "": return True
if int(settings_toml["smtp"]["smtp_port"]) == 0: return True
if settings_toml["emails"]["ids"] == []: return True
if settings_toml["emails"]["subjects"] == []: return True
if settings_toml["emails"]["writeups"] == []: return True
if settings_toml["emails"]["isfromfile"] == []: return True
if settings_toml["csv"]["titles"] == []: return True
if settings_toml["csv"]["placeholders"] == []: return True
if str(settings_toml["csv"]["output_folder"]).strip() == "": return True
return False
# Save data to settings.toml file
def save_to_toml(toml_data):
path = pathlib.Path(__file__).parent / "settings.toml"
settings_file = path.open(mode="wb")
tomli_w.dump(toml_data, settings_file)
settings_file.close()