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 '