2.0大版本更新
This commit is contained in:
1 parent
1135e05b7b
commit
cf5ff10e5d
16 files changed
+957
-282
No files matched your search
Binary file not shown.
Binary file not shown.
+38
-2
@@ -22,10 +22,46 @@ def create_database():
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def parse_pub_date(pub_date_str):
|
||||
if not pub_date_str:
|
||||
return pub_date_str
|
||||
|
||||
# 定义多种日期格式
|
||||
date_formats = [
|
||||
# ISO 8601 格式(带 T)
|
||||
'%Y-%m-%dT%H:%M:%S',
|
||||
'%Y-%m-%dT%H:%M:%S%z',
|
||||
# 标准日期时间格式
|
||||
'%Y-%m-%d %H:%M:%S',
|
||||
'%Y-%m-%d %H:%M',
|
||||
'%Y-%m-%d',
|
||||
# RFC 822/1123 格式(英文星期和月份)
|
||||
'%a, %d %b %Y %H:%M:%S %z',
|
||||
'%a, %d %b %Y %H:%M:%S GMT',
|
||||
'%a, %d %b %Y %H:%M:%S',
|
||||
# 其他常见格式
|
||||
'%d %b %Y %H:%M:%S %z',
|
||||
'%d %b %Y %H:%M:%S',
|
||||
]
|
||||
|
||||
for fmt in date_formats:
|
||||
try:
|
||||
pub_date = datetime.strptime(pub_date_str, fmt)
|
||||
# 格式化输出为统一格式
|
||||
return pub_date.strftime('%Y-%m-%d %H:%M:%S')
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
# 如果所有格式都失败,返回原始字符串
|
||||
return pub_date_str
|
||||
|
||||
def insert_data(data):
|
||||
conn = sqlite3.connect('./resources/db/uni_rss.db')
|
||||
cursor = conn.cursor()
|
||||
for entry in data:
|
||||
# 使用新的日期解析函数
|
||||
formatted_pub_date = parse_pub_date(entry['published'])
|
||||
|
||||
cursor.execute('''
|
||||
SELECT 1 FROM articles WHERE title = ? AND author = ?
|
||||
''', (entry['title'], entry['author']))
|
||||
@@ -34,7 +70,7 @@ def insert_data(data):
|
||||
cursor.execute('''
|
||||
INSERT INTO articles (title, link, author, description, pubDate, source)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
''', (entry['title'], entry['link'], entry['author'], entry['description'], entry['published'], entry['source']))
|
||||
''', (entry['title'], entry['link'], entry['author'], entry['description'], formatted_pub_date, entry['source']))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -77,7 +113,7 @@ def select_articles(uni_rss_switch, Unity):
|
||||
|
||||
# 获取当前日期和时间
|
||||
now = datetime.now()
|
||||
two_days_ago = now - timedelta(days=2)
|
||||
two_days_ago = now - timedelta(days=200)
|
||||
|
||||
if uni_rss_switch == False:
|
||||
# 查询指定时间段内的数据
|
||||
|
||||
Reference in new issue
Block a user