added function to insert translated list of content

This commit is contained in:
brian
2022-12-18 12:00:55 +00:00
parent d52a9e3558
commit fc04f49a00
+17
View File
@@ -171,6 +171,23 @@ def insert_list(username_list, timestamp_list, content_list):
except Exception as e: except Exception as e:
logging.warning(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(): def get_content():
with Data_table() as dt: with Data_table() as dt:
query = f'SELECT * FROM {dt._name} ORDER BY time DESC ' query = f'SELECT * FROM {dt._name} ORDER BY time DESC '