Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from termcolor import cprint
- _help = False
- _user = ""
- def main():
- cprint('Введите help - для получения справки\n')
- db = loadPass()
- flagAuth = False
- while True:
- inp = input()
- x = inp.split()
- cprint('Введите help - для получения справки\n')
- print(inp, '\n')
- if x[0] == 'help':
- help_m()
- elif x[0] == 'auth':
- flagAuth = auth_m(db, x)
- elif x[0] == 'exit':
- cprint('До свидания!\n')
- break
- elif checkAuth(flagAuth):
- if x[0] == 'list':
- list_m()
- elif x[0] == 'read':
- read_m(x)
- elif x[0] == 'send':
- send_m(x)
- else:
- cprint('Ошибка: Неизвестная команда\n')
- def checkAuth(flag):
- if flag:
- return True
- else:
- if _help:
- help_m()
- cprint('Ошибка: Сначала авторизуйтесь\n', 'red')
- return False
- def help_m():
- global _help
- _help = True
- cprint('auth user pass - авторизоваться, user - логин, pass - пароль', 'yellow')
- cprint('list — показать список сообщений', 'yellow')
- cprint('read msg — вывести сообщение под номером msg', 'yellow')
- cprint('send user — ввод сообщения для пользователя', 'yellow')
- cprint('exit — выход\n', 'yellow')
- def list_m():
- if not _help:
- help_m()
- for file in os.listdir('.\\messages\\' + _user):
- if os.path.isfile(os.path.join('.\\messages\\' + _user, file)):
- print(file)
- print()
- def send_m(x):
- if not _help:
- help_m()
- path = '.\\messages\\' + x[1]
- count = len(os.listdir(path))
- theme = input("\nВведите тему письма: ")
- fileName = str(count + 1) + ' ' + theme
- file = open(path + '\\' + fileName + '.txt', 'w')
- file.write(input("\nВведите сообщение: "))
- file.close()
- print("\nСообщение отправлено.")
- def read_m(x):
- if not _help:
- help_m()
- for file in os.listdir('.\\messages\\' + _user):
- for split_file in file.split():
- if split_file[0] == x[1]:
- file_r = open('.\\messages\\' + _user + '\\' + file, 'r')
- print(file_r.readline())
- def loadPass():
- db = {}
- with open("pass.txt") as file:
- for line in file:
- key, value = line.split()
- db[key] = value
- return db
- def auth_m(db, x):
- global _help
- global _user
- if not _help:
- help_m()
- if len(x) < 3:
- cprint('Ошибка: Введите логин и пароль\n', 'red')
- return
- flagAuth = False
- for user in db:
- if user == x[1]:
- if db.get(user) == x[2]:
- cprint('Авторизация прошла успешно\n', 'blue')
- flagAuth = True
- _user = x[1]
- mkdir()
- break
- else:
- cprint('Ошибка: Неверный логин или пароль\n', 'red')
- return flagAuth
- def mkdir():
- global _user
- if _user != "":
- if not os.path.exists(".\\messages\\" + _user):
- os.mkdir(".\\messages\\" + _user)
- main()
Advertisement
Add Comment
Please, Sign In to add comment