From 840f1b45112136465e7f5c85a44c5e542cdd8294 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Tue, 27 Aug 2019 15:33:44 +0200 Subject: [PATCH] default db data --- src/Utils.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Utils.py b/src/Utils.py index 01d9742..94cf57e 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -2,9 +2,23 @@ from telegram import Update from telegram.ext import PicklePersistence, Updater from yaml import load, Loader from enum import Enum +import pickle -config = load(open('./config.yml', 'r'), Loader=Loader) -persistence = PicklePersistence('./data.db') +DB_FILE = './data.db' +CONFIG_FILE = './config.yml' +DEFAULT_DATA = { + 'user_data': {}, + 'chat_data': {}, + 'conversations': {}, +} + +try: + pickle.load(open(DB_FILE, 'rb')) +except: + pickle.dump(DEFAULT_DATA, open(DB_FILE, 'wb')) + +config = load(open(CONFIG_FILE, 'r'), Loader=Loader) +persistence = PicklePersistence(DB_FILE) updater: Updater = Updater(config['token'], use_context=True, persistence=persistence)