xlive/app/database.py

28 lines
2.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sqlite3
def init_db():
DATABASE = 'platforms.db'
with sqlite3.connect(DATABASE) as conn:
conn.execute('''CREATE TABLE IF NOT EXISTS platforms
(id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
image TEXT NOT NULL,
description TEXT NOT NULL,
link TEXT NOT NULL)''')
# 检查是否已有数据存在
cursor = conn.execute('SELECT COUNT(*) FROM platforms')
count = cursor.fetchone()[0]
if count == 0:
# 插入默认平台数据
default_platforms = [
('美国体育电视网', 'https://dw.gdzx.xyz/espn.png', 'ESPN美国体育电视网是美国最大的体育电视网络提供实时体育赛事直播、新闻报道、赛后分析和专题节目', 'http://14.17.80.242:18080/espn/live.flv'),
('美国全国广播公司新闻', 'https://dw.gdzx.xyz/nbc.png', '美国全国广播公司新闻网提供全天候新闻报道、深度调查和综合新闻分析。', 'http://14.17.80.242:18080/nbc/live.flv'),
('美国全国公共广播电台', 'https://dw.gdzx.xyz/npr.png', '美国全国公共广播电台NPR电视节目提供深入新闻报道、文化和教育内容。', 'http://14.17.80.242:18080/npr/live.flv'),
('美国福克斯新闻网', 'https://dw.gdzx.xyz/fox.png', '美国福克斯新闻电视台Fox News提供全天候新闻报道和保守派观点的政治评论节目。', 'http://14.17.80.242:18080/fox/live.flv'),
('美国国家地理频道', 'https://dw.gdzx.xyz/ngeo.png', '美国国家地理频道提供高质量纪录片和教育节目,探索自然、科学和文化。', 'http://14.17.80.242:18080/ng/live.flv'),
('中国中央电视台', 'https://dw.gdzx.xyz/cctv.png', '国中央电视台CCTV是中国最大的国家电视台提供新闻、娱乐和教育节目。', 'http://14.17.80.242:18080/cctv1/live.flv')
]
conn.executemany('INSERT INTO platforms (name, image, description, link) VALUES (?, ?, ?, ?)', default_platforms)