From cf6521ff4a5f88dea0888f2ea8f1c2f66fd92118 Mon Sep 17 00:00:00 2001 From: trueold89 Date: Tue, 31 Oct 2023 01:00:58 +0300 Subject: [PATCH] Init db.py --- db.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 db.py diff --git a/db.py b/db.py new file mode 100644 index 0000000..5058a27 --- /dev/null +++ b/db.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +# -- coding: utf-8 -- + +import pickle, os + +PATH = "/etc/bot/" +AUTH_FILE= "auth.pkl" +DIR_FILE = "dir.pkl" + +def check(type,FILE): + if type == 'dir': + if os.path.exists(PATH) == False: + os.mkdir(PATH) + return True + elif type == 'obj': + if os.path.exists(f'{PATH}{FILE}'): + return True + else: + return False + +def write(obj,FILE): + if check('dir',None): + with open(f'{PATH}{FILE}',"wb") as file: + pickle.dump(obj,file) + +def read(FILE): + with open(f'{PATH}{FILE}',"rb") as file: + obj = pickle.load(file) + return obj