update
Browse files- .gitignore +24 -0
- examples/make_test_audios.py +144 -0
- project_settings.py +27 -0
- requirements.txt +3 -0
- toolbox/__init__.py +6 -0
- toolbox/json/__init__.py +6 -0
- toolbox/json/misc.py +63 -0
- toolbox/os/__init__.py +6 -0
- toolbox/os/environment.py +114 -0
- toolbox/os/other.py +9 -0
.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
.git/
|
| 3 |
+
.idea/
|
| 4 |
+
|
| 5 |
+
**/flagged/
|
| 6 |
+
**/log/
|
| 7 |
+
**/logs/
|
| 8 |
+
**/__pycache__/
|
| 9 |
+
|
| 10 |
+
data/es-MX
|
| 11 |
+
data/pt-BR
|
| 12 |
+
data/52
|
| 13 |
+
data/55
|
| 14 |
+
data/52.zip
|
| 15 |
+
data/55.zip
|
| 16 |
+
/docs/
|
| 17 |
+
/dotenv/
|
| 18 |
+
/hub_datasets/
|
| 19 |
+
/trained_models/
|
| 20 |
+
/temp/
|
| 21 |
+
|
| 22 |
+
/data/**/*.wav
|
| 23 |
+
|
| 24 |
+
**/*.wav
|
examples/make_test_audios.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import argparse
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import shutil
|
| 7 |
+
|
| 8 |
+
import pandas as pd
|
| 9 |
+
|
| 10 |
+
from project_settings import project_path
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def get_args():
|
| 14 |
+
parser = argparse.ArgumentParser()
|
| 15 |
+
parser.add_argument(
|
| 16 |
+
"--audio_dir",
|
| 17 |
+
default=(project_path / "data/es-MX").as_posix(),
|
| 18 |
+
# default=(project_path / "data/pt-BR").as_posix(),
|
| 19 |
+
type=str
|
| 20 |
+
)
|
| 21 |
+
parser.add_argument(
|
| 22 |
+
"--output_dir",
|
| 23 |
+
default=(project_path / "data/52").as_posix(),
|
| 24 |
+
# default=(project_path / "data/55").as_posix(),
|
| 25 |
+
type=str
|
| 26 |
+
)
|
| 27 |
+
args = parser.parse_args()
|
| 28 |
+
return args
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
quantity_to_use = """
|
| 32 |
+
bell_and_mute: 2, 2%
|
| 33 |
+
bell_and_mute_1_second_then_voicemail: 1, 1%
|
| 34 |
+
bell_and_not_connected: 17, 17%
|
| 35 |
+
bell_and_voice: 1, 1%
|
| 36 |
+
bell_and_voicemail: 6, 6%
|
| 37 |
+
busy_and_not_connected: 11, 11%
|
| 38 |
+
busy_or_disconnected_or_out_of_coverage_and_not_connected: 1, 1%
|
| 39 |
+
disconnected_or_out_of_service_and_not_connected: 1, 1%
|
| 40 |
+
early_media_voicemail_and_not_connected: 11, 11%
|
| 41 |
+
early_media_voicemail_and_voicemail: 30, 30%
|
| 42 |
+
early_media_voicemail_is_full_and_not_connected: 9, 9%
|
| 43 |
+
music_and_voicemail: 2, 2%
|
| 44 |
+
mute_and_not_connected: 1, 1%
|
| 45 |
+
mute_and_voicemail: 2, 2%
|
| 46 |
+
out_of_service_and_not_connected: 2, 2%
|
| 47 |
+
unavailable_and_not_connected: 1, 1%
|
| 48 |
+
unavailable_or_out_of_service_and_not_connected: 2, 2%
|
| 49 |
+
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
quantity_to_use2 = """
|
| 54 |
+
bell_and_di_then_mute: 3, 3%
|
| 55 |
+
bell_and_mute: 8, 8%
|
| 56 |
+
bell_and_mute_4_second_then_voicemail: 1, 1%
|
| 57 |
+
bell_and_noise_mute: 1, 1%
|
| 58 |
+
bell_and_not_connected: 8, 8%
|
| 59 |
+
bell_and_voice: 10, 10%
|
| 60 |
+
bell_and_voicemail: 6, 6%
|
| 61 |
+
blocked_or_cannot_receive_this_call: 2, 2%
|
| 62 |
+
busy_and_not_connected: 1, 1%
|
| 63 |
+
early_media_voicemail_and_di_then_mute: 5, 5%
|
| 64 |
+
early_media_voicemail_and_not_connected: 46, 46%
|
| 65 |
+
early_media_voicemail_and_not_connected2: 2, 2%
|
| 66 |
+
invalid_number: 2, 2%
|
| 67 |
+
mute_and_mute: 2, 2%
|
| 68 |
+
mute_and_noise_mute: 1, 1%
|
| 69 |
+
mute_and_not_connected: 1, 1%
|
| 70 |
+
unable_to_complete_this_call: 1, 1%
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def main():
|
| 75 |
+
args = get_args()
|
| 76 |
+
audio_dir = Path(args.audio_dir)
|
| 77 |
+
output_dir = Path(args.output_dir)
|
| 78 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 79 |
+
suffix_count = 0
|
| 80 |
+
|
| 81 |
+
call_id_to_wav_file_list = defaultdict(list)
|
| 82 |
+
for filename in audio_dir.glob("**/*.wav"):
|
| 83 |
+
splits = filename.stem.split("_")
|
| 84 |
+
call_id = splits[3]
|
| 85 |
+
language = splits[4]
|
| 86 |
+
scene_id = splits[5]
|
| 87 |
+
call_id_to_wav_file_list[call_id].append(filename)
|
| 88 |
+
print(f"count: {len(call_id_to_wav_file_list)}")
|
| 89 |
+
|
| 90 |
+
rows = quantity_to_use.strip().split("\n")
|
| 91 |
+
|
| 92 |
+
result = list()
|
| 93 |
+
for row in rows:
|
| 94 |
+
splits = row.strip().split(",", maxsplit=1)
|
| 95 |
+
row = splits[0]
|
| 96 |
+
splits = row.strip().split(":", maxsplit=1)
|
| 97 |
+
|
| 98 |
+
folder_name = splits[0].strip()
|
| 99 |
+
need_count = splits[1].strip()
|
| 100 |
+
need_count = int(need_count)
|
| 101 |
+
|
| 102 |
+
candidate_dir = audio_dir / folder_name
|
| 103 |
+
candidates = list(candidate_dir.glob("active_media_r_*.wav"))
|
| 104 |
+
|
| 105 |
+
print(f"candidates count: {len(candidates)}, need count: {need_count}, folder_name: {folder_name}")
|
| 106 |
+
candidates = candidates[:need_count]
|
| 107 |
+
for filename in candidates:
|
| 108 |
+
splits = filename.stem.split("_")
|
| 109 |
+
call_id = splits[3]
|
| 110 |
+
|
| 111 |
+
tgt_dir = output_dir / f"{suffix_count:02}"
|
| 112 |
+
tgt_dir.mkdir(parents=True, exist_ok=True)
|
| 113 |
+
suffix_count += 1
|
| 114 |
+
wav_file_list = call_id_to_wav_file_list[call_id]
|
| 115 |
+
|
| 116 |
+
for wav_file in wav_file_list:
|
| 117 |
+
|
| 118 |
+
if wav_file.stem.startswith("active_media_r"):
|
| 119 |
+
tgt_filename = tgt_dir / f"active_media_{call_id}.wav"
|
| 120 |
+
elif wav_file.stem.startswith("early_media_r"):
|
| 121 |
+
tgt_filename = tgt_dir / f"early_media_{call_id}.wav"
|
| 122 |
+
elif wav_file.stem.startswith("active_media_w"):
|
| 123 |
+
continue
|
| 124 |
+
else:
|
| 125 |
+
raise AssertionError
|
| 126 |
+
shutil.copy(
|
| 127 |
+
wav_file.as_posix(),
|
| 128 |
+
tgt_filename.as_posix(),
|
| 129 |
+
)
|
| 130 |
+
result.append({
|
| 131 |
+
"suffix": f"{suffix_count-1:02}",
|
| 132 |
+
"label": folder_name
|
| 133 |
+
})
|
| 134 |
+
result = pd.DataFrame(result)
|
| 135 |
+
result.to_excel(
|
| 136 |
+
output_dir / "readme.xlsx",
|
| 137 |
+
index=False
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
return
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
main()
|
project_settings.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import os
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
from toolbox.os.environment import EnvironmentManager
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
project_path = os.path.abspath(os.path.dirname(__file__))
|
| 10 |
+
project_path = Path(project_path)
|
| 11 |
+
|
| 12 |
+
environment = EnvironmentManager(
|
| 13 |
+
path=os.path.join(project_path, "dotenv"),
|
| 14 |
+
env=os.environ.get("environment", "dev"),
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
temp_dir = project_path / "temp"
|
| 18 |
+
temp_dir.mkdir(parents=True, exist_ok=True)
|
| 19 |
+
|
| 20 |
+
time_zone_info = "Asia/Shanghai"
|
| 21 |
+
|
| 22 |
+
log_directory = project_path / "logs"
|
| 23 |
+
log_directory.mkdir(parents=True, exist_ok=True)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
pass
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python-dotenv==1.0.1
|
| 2 |
+
pandas
|
| 3 |
+
openpyxl
|
toolbox/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
if __name__ == "__main__":
|
| 6 |
+
pass
|
toolbox/json/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
if __name__ == '__main__':
|
| 6 |
+
pass
|
toolbox/json/misc.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
from typing import Callable
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def traverse(js, callback: Callable, *args, **kwargs):
|
| 7 |
+
if isinstance(js, list):
|
| 8 |
+
result = list()
|
| 9 |
+
for l in js:
|
| 10 |
+
l = traverse(l, callback, *args, **kwargs)
|
| 11 |
+
result.append(l)
|
| 12 |
+
return result
|
| 13 |
+
elif isinstance(js, tuple):
|
| 14 |
+
result = list()
|
| 15 |
+
for l in js:
|
| 16 |
+
l = traverse(l, callback, *args, **kwargs)
|
| 17 |
+
result.append(l)
|
| 18 |
+
return tuple(result)
|
| 19 |
+
elif isinstance(js, dict):
|
| 20 |
+
result = dict()
|
| 21 |
+
for k, v in js.items():
|
| 22 |
+
k = traverse(k, callback, *args, **kwargs)
|
| 23 |
+
v = traverse(v, callback, *args, **kwargs)
|
| 24 |
+
result[k] = v
|
| 25 |
+
return result
|
| 26 |
+
elif isinstance(js, int):
|
| 27 |
+
return callback(js, *args, **kwargs)
|
| 28 |
+
elif isinstance(js, str):
|
| 29 |
+
return callback(js, *args, **kwargs)
|
| 30 |
+
else:
|
| 31 |
+
return js
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def demo1():
|
| 35 |
+
d = {
|
| 36 |
+
"env": "ppe",
|
| 37 |
+
"mysql_connect": {
|
| 38 |
+
"host": "$mysql_connect_host",
|
| 39 |
+
"port": 3306,
|
| 40 |
+
"user": "callbot",
|
| 41 |
+
"password": "NxcloudAI2021!",
|
| 42 |
+
"database": "callbot_ppe",
|
| 43 |
+
"charset": "utf8"
|
| 44 |
+
},
|
| 45 |
+
"es_connect": {
|
| 46 |
+
"hosts": ["10.20.251.8"],
|
| 47 |
+
"http_auth": ["elastic", "ElasticAI2021!"],
|
| 48 |
+
"port": 9200
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
def callback(s):
|
| 53 |
+
if isinstance(s, str) and s.startswith('$'):
|
| 54 |
+
return s[1:]
|
| 55 |
+
return s
|
| 56 |
+
|
| 57 |
+
result = traverse(d, callback=callback)
|
| 58 |
+
print(result)
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == '__main__':
|
| 63 |
+
demo1()
|
toolbox/os/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
if __name__ == '__main__':
|
| 6 |
+
pass
|
toolbox/os/environment.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from dotenv.main import DotEnv
|
| 8 |
+
|
| 9 |
+
from toolbox.json.misc import traverse
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class EnvironmentManager(object):
|
| 13 |
+
def __init__(self, path, env, override=False):
|
| 14 |
+
filename = os.path.join(path, '{}.env'.format(env))
|
| 15 |
+
self.filename = filename
|
| 16 |
+
|
| 17 |
+
load_dotenv(
|
| 18 |
+
dotenv_path=filename,
|
| 19 |
+
override=override
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
self._environ = dict()
|
| 23 |
+
|
| 24 |
+
def open_dotenv(self, filename: str = None):
|
| 25 |
+
filename = filename or self.filename
|
| 26 |
+
dotenv = DotEnv(
|
| 27 |
+
dotenv_path=filename,
|
| 28 |
+
stream=None,
|
| 29 |
+
verbose=False,
|
| 30 |
+
interpolate=False,
|
| 31 |
+
override=False,
|
| 32 |
+
encoding="utf-8",
|
| 33 |
+
)
|
| 34 |
+
result = dotenv.dict()
|
| 35 |
+
return result
|
| 36 |
+
|
| 37 |
+
def get(self, key, default=None, dtype=str):
|
| 38 |
+
result = os.environ.get(key)
|
| 39 |
+
if result is None:
|
| 40 |
+
if default is None:
|
| 41 |
+
result = None
|
| 42 |
+
else:
|
| 43 |
+
result = default
|
| 44 |
+
else:
|
| 45 |
+
result = dtype(result)
|
| 46 |
+
self._environ[key] = result
|
| 47 |
+
return result
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
_DEFAULT_DTYPE_MAP = {
|
| 51 |
+
'int': int,
|
| 52 |
+
'float': float,
|
| 53 |
+
'str': str,
|
| 54 |
+
'json.loads': json.loads
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class JsonConfig(object):
|
| 59 |
+
"""
|
| 60 |
+
将 json 中, 形如 `$float:threshold` 的值, 处理为:
|
| 61 |
+
从环境变量中查到 threshold, 再将其转换为 float 类型.
|
| 62 |
+
"""
|
| 63 |
+
def __init__(self, dtype_map: dict = None, environment: EnvironmentManager = None):
|
| 64 |
+
self.dtype_map = dtype_map or _DEFAULT_DTYPE_MAP
|
| 65 |
+
self.environment = environment or os.environ
|
| 66 |
+
|
| 67 |
+
def sanitize_by_filename(self, filename: str):
|
| 68 |
+
with open(filename, 'r', encoding='utf-8') as f:
|
| 69 |
+
js = json.load(f)
|
| 70 |
+
|
| 71 |
+
return self.sanitize_by_json(js)
|
| 72 |
+
|
| 73 |
+
def sanitize_by_json(self, js):
|
| 74 |
+
js = traverse(
|
| 75 |
+
js,
|
| 76 |
+
callback=self.sanitize,
|
| 77 |
+
environment=self.environment
|
| 78 |
+
)
|
| 79 |
+
return js
|
| 80 |
+
|
| 81 |
+
def sanitize(self, string, environment):
|
| 82 |
+
"""支持 $ 符开始的, 环境变量配置"""
|
| 83 |
+
if isinstance(string, str) and string.startswith('$'):
|
| 84 |
+
dtype, key = string[1:].split(':')
|
| 85 |
+
dtype = self.dtype_map[dtype]
|
| 86 |
+
|
| 87 |
+
value = environment.get(key)
|
| 88 |
+
if value is None:
|
| 89 |
+
raise AssertionError('environment not exist. key: {}'.format(key))
|
| 90 |
+
|
| 91 |
+
value = dtype(value)
|
| 92 |
+
result = value
|
| 93 |
+
else:
|
| 94 |
+
result = string
|
| 95 |
+
return result
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def demo1():
|
| 99 |
+
import json
|
| 100 |
+
|
| 101 |
+
from settings import project_path
|
| 102 |
+
|
| 103 |
+
environment = EnvironmentManager(
|
| 104 |
+
path=os.path.join(project_path, 'server/callbot_server/dotenv'),
|
| 105 |
+
env='dev',
|
| 106 |
+
)
|
| 107 |
+
init_scenes = environment.get(key='init_scenes', dtype=json.loads)
|
| 108 |
+
print(init_scenes)
|
| 109 |
+
print(environment._environ)
|
| 110 |
+
return
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
if __name__ == '__main__':
|
| 114 |
+
demo1()
|
toolbox/os/other.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import inspect
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def pwd():
|
| 6 |
+
"""你在哪个文件调用此函数, 它就会返回那个文件所在的 dir 目标"""
|
| 7 |
+
frame = inspect.stack()[1]
|
| 8 |
+
module = inspect.getmodule(frame[0])
|
| 9 |
+
return os.path.dirname(os.path.abspath(module.__file__))
|