diff --git a/README.md b/README.md index 97dbdf3..68a86b4 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ pip install geopy pip install maidenhead pip install beautifulsoup4 pip install dadjokes +pip install pickle ``` dev enhancments if using visual studio diff --git a/bbstools.py b/bbstools.py index ddb863f..d048917 100644 --- a/bbstools.py +++ b/bbstools.py @@ -2,26 +2,36 @@ # K7MHI Kelly Keeton 2024 from dadjokes import Dadjoke # pip install dadjokes +import pickle # pip install pickle +import os -# global message list, later we will use a database on disk -bbs_messages = [[1, "Welcome to meshBBS", "Welcome to the BBS, please post a message!"]] +# global message list +bbs_messages = [] def tell_joke(): # tell a dad joke, does it need an explanationn :) dadjoke = Dadjoke() return dadjoke.joke -def create_bbsdb(): - # create a database file for the bbs messages - pass - def load_bbsdb(): + global bbs_messages # load the bbs messages from the database file - pass + if not os.path.exists('bbsdb.pkl'): + # if not, create it + bbs_messages = [[1, "Welcome to meshBBS", "Welcome to the BBS, please post a message!"]] + print ("\nSystem: Creating new bbsdb.pkl") + with open('bbsdb.pkl', 'wb') as f: + pickle.dump(bbs_messages, f) + else: + with open('bbsdb.pkl', 'rb') as f: + bbs_messages = pickle.load(f) def save_bbsdb(): + global bbs_messages # save the bbs messages to the database file - pass + print ("System: Saving bbsdb.pkl\n") + with open('bbsdb.pkl', 'wb') as f: + pickle.dump(bbs_messages, f) def bbs_help(): # help message @@ -67,5 +77,6 @@ def bbs_read_message(messageID = 0): else: return "Please specify a message number to read." - +#initialize the bbsdb +load_bbsdb() diff --git a/mesh_bot.py b/mesh_bot.py index 1fa3931..94dcc75 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -343,6 +343,11 @@ def send_message(message, ch, nodeid): def exit_handler(signum, frame): print("\nSystem: Closing Autoresponder") interface.close() + print("System: Interface Closed") + print("Saving BBS Messages") + save_bbsdb() + print("System: BBS Messages Saved") + print("System: Exiting") exit (0) print ("\nMeshtastic Autoresponder MESH Bot CTL+C to exit\n") diff --git a/requirements.txt b/requirements.txt index 3b2eb90..ca79011 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ maidenhead beautifulsoup4 dadjokes mock -unittest \ No newline at end of file +unittest +pickle \ No newline at end of file