Spaces:
Running
Running
import sqlite3 | |
def create_table(): | |
# Connect to SQLite database (it will create the file if it doesn't exist) | |
conn = sqlite3.connect("news_aggregator.db") | |
cursor = conn.cursor() | |
# Create articles table | |
cursor.execute(''' | |
CREATE TABLE IF NOT EXISTS articles ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
title TEXT NOT NULL, | |
description TEXT, | |
link TEXT, | |
topic TEXT, | |
date_published TEXT | |
) | |
''') | |
# Commit and close connection | |
conn.commit() | |
conn.close() | |
# Run the function to create the table | |
create_table() | |