From fc04f49a000a778cdc1e004c382a334426355fdd Mon Sep 17 00:00:00 2001 From: brian Date: Sun, 18 Dec 2022 12:00:55 +0000 Subject: [PATCH] added function to insert translated list of content --- code/database.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/code/database.py b/code/database.py index 64f3174..09a1d97 100644 --- a/code/database.py +++ b/code/database.py @@ -171,6 +171,23 @@ def insert_list(username_list, timestamp_list, content_list): except Exception as e: logging.warning(e) +def insert_translated_list(content_list, id_list): + with Data_table() as dt: + for id, content in zip(id_list, content_list): + try: + val_dict = { + 'id': id, + 'content_en': content + } + query = ( + f'UPDATE {dt._name} ' + ' SET content_en = (%(content_en)s) ' + 'WHERE id = (%(id)s) ' + ) + dt.execute(query, val_dict) + except Exception as e: + print(f'error when updating database: {e}') + def get_content(): with Data_table() as dt: query = f'SELECT * FROM {dt._name} ORDER BY time DESC '