Exemplo n.º 1
0
def fetch_faq_data():
    """Creates FAQ table and populates it with data in faq.json"""
    # create faq table
    print(f"Creating faq table in data_storage.db")
    data_storage = Database("data_storage.db")
    data_storage.create_faq_table()
    # load faq data
    with open(DATA_DIR + "faq.json") as json_file:
        data = json.load(json_file)
    # insert data to db
    print(f"Inserting data from faq.json file...")
    for faq in data:
        data_storage.insert_faq(faq)
    data_storage.close_connection()
Exemplo n.º 2
0
 def insert_faq_to_db(
     self, db_name, faq_table_name, question, answer, author, keywords
 ):
     """Inserts FAQ values to db"""
     # prepare data_storage
     data_storage = Database(f"{db_name}.db")
     # create table if not exists
     tables_in_db = list([table[0] for table in data_storage.get_tables()])
     if faq_table_name not in tables_in_db:
         print(f"Creating '{faq_table_name}' table in {db_name}.db")
         data_storage.create_faq_table(table_name=f"{faq_table_name}")
     # insert row
     faq_obj = FAQ(
         question=question, answer=answer, author=author, keywords=keywords
     )
     data_storage.insert_faq(faq_obj, table_name=faq_table_name)
     print(f"FAQ object inserted in '{faq_table_name}' table on {db_name}.db!")
     data_storage.close_connection()