Python DB
1 min readMar 15, 2022
# How to proceed?
# 1 - way
# ---------------------
# - Step - 1 : Read all data from web and keep in some variable
# - Step - 2 : Extract using regex and keep result in one more variable
# - Step - 3 : Create Database and table
# - Step - 4 : Send extracted data to database table
# ---------------------
# 2 - way
# ---------------------
# - Step - 1 : Create database and table
# - Step - 2 : Read line by line from website
# - Step - 3 : Extract each line using regex
# - Step - 4 : send each line extracted data to table
# ---------------------
print("# - Step - 1 : Create database and table")
print("-"*20)
# -------------------------
import sqlite3
print("Creating/Connecting to DB")
my_db_connection = sqlite3.connect('my_database.sqlite3')
print("Done")
print("Obtain cursor object, which help us to communicate with DB")
my_db_cursor = my_db_connection.cursor()
print("Done")
print("Creating table if not exists..")
my_query = '''
CREATE TABLE IF NOT EXISTS MY_LOG_DATA(
NAME VARCHAR(100),
SCORE VARCHAR(100)
)
'''
my_db_cursor.execute(my_query)
print("Done")
my_query = f"INSERT INTO MY_LOG_DATA VALUES('{name}','{score}')"
print("Executing Query: ", my_query)
my_db_cursor.execute(my_query)
print("one row insert done")