timmy / 使用 SQLite 儲存與管理 RSS 資料
0 Kedvelések
0 forkok
1 fájlok
Utoljára aktív 10 months ago
這段程式碼使用 SQLite 初始化資料庫與表格,並提供函數將條目插入表格,同時處理重複條目的情況。測試範例展示如何插入一筆包含標題、連結、發布日期及描述的資料。
| 1 | import sqlite3 |
| 2 | |
| 3 | |
| 4 | # 初始化資料庫及表格 |
| 5 | def initialize_db(db_name="database.db", table_name="entries"): |
| 6 | conn = sqlite3.connect(db_name) |
| 7 | cursor = conn.cursor() |
| 8 | cursor.execute( |
| 9 | f""" |
| 10 | CREATE TABLE IF NOT EXISTS {table_name} ( |
Újabb
Régebbi