From d602fda7c927e1791a295ec33bba4075d9390561 Mon Sep 17 00:00:00 2001 From: simplypower-bbj Date: Sat, 17 Dec 2022 01:12:31 +0100 Subject: [PATCH] added function to insert lists of data --- code/database.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/code/database.py b/code/database.py index 3e5be74..509b88a 100644 --- a/code/database.py +++ b/code/database.py @@ -156,4 +156,17 @@ def insert(username, timestamp, content): 'content': content } with Data_table() as dt: - dt.insert(val_dict) \ No newline at end of file + dt.insert(val_dict) + +def insert_list(username_list, timestamp_list, content_list): + with Data_table() as dt: + for username, timestamp, content in zip(username_list, timestamp_list, content_list): + try: + val_dict = { + 'username': username, + 'time': timestamp, + 'content': content + } + dt.insert(val_dict) + except Exception as e: + logging.warning(e) \ No newline at end of file