(feat): Added dotenv and updated the database to run with DATABASE_URL
This commit is contained in:
parent
328f604c08
commit
0a86fde915
2 changed files with 10 additions and 3 deletions
10
database.py
10
database.py
|
|
@ -1,7 +1,13 @@
|
|||
import sqlite3
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL")
|
||||
|
||||
def init_db():
|
||||
conn = sqlite3.connect('subscribers.db')
|
||||
conn = sqlite3.connect(DATABASE_URL)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS subscribers (
|
||||
|
|
@ -14,7 +20,7 @@ def init_db():
|
|||
|
||||
def add_email(email):
|
||||
try:
|
||||
conn = sqlite3.connect('subscribers.db')
|
||||
conn = sqlite3.connect(DATABASE_URL)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("INSERT INTO subscribers (email) VALUES (?)", (email,))
|
||||
conn.commit()
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
flask
|
||||
flask
|
||||
python-dotenv
|
||||
Loading…
Add table
Add a link
Reference in a new issue