добавлено создание подкаталогов, диалог о существующем ключе api в боте

This commit is contained in:
2023-03-04 14:03:27 +03:00
parent 823ffdd607
commit 2c0e9803d2
2 changed files with 33 additions and 8 deletions

View File

@ -51,6 +51,8 @@ def create_dir(directory):
"""Проверка и создание директории"""
if not os.path.exists(directory):
os.mkdir(directory)
os.chdir("..")
os.mkdir("maps")
def check_int(number=""):

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
import errno
import time
import os
import telebot
@ -11,14 +12,35 @@ import hlna
list_config = hlna.list_config
def read_config():
if not f"{hlna.dir_config}hlna_bot":
def start():
if not os.path.exists(f"{hlna.dir_config}bot/hlna_bot"):
key_api = input("Укажите ключ бота\n")
os.chdir(hlna.dir_config)
try:
os.mkdir("bot")
except OSError as e:
if e.errno == errno.EEXIST:
print('Каталог создан')
else:
raise
create_config(key_api)
else:
with open(f"{hlna.dir_config}hlna_bot", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
return data[0]
x = input("Уже есть запомненный ключа api. Запустить его? Y/n \n")
if x == "":
x = "y"
elif x == "y":
read_config()
elif x == "n":
os.remove(f"{hlna.dir_config}bot/hlna_bot")
start()
def read_config():
with open(f"{hlna.dir_config}bot/hlna_bot", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
return data[0]
def create_config(key_api):
k_api = key_api
config_hlna_bot = [
@ -26,12 +48,12 @@ def create_config(key_api):
'key_api': k_api,
}
]
with open(f"{hlna.dir_config}hlna_bot", 'w') as yamlfile:
with open(f"{hlna.dir_config}bot/hlna_bot", 'w') as yamlfile:
yaml.dump(config_hlna_bot, yamlfile)
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
print(colorama.Fore.GREEN + "Конфиг бота создан" + colorama.Style.RESET_ALL)
return k_api
start()
data = read_config()
k_api = data['key_api']
@ -71,6 +93,7 @@ def m_chose(m):
reply_markup=menu_install)
hlna_bot.register_next_step_handler(m, m_install)
else:
hlna.read_yaml(list_config, flag=True)
menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True)
for i in list_config:
k_mapname = types.KeyboardButton(f"{i}")