You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
import psycopg2
|
|
|
|
# 数据库连接参数
|
|
db_params = {
|
|
'dbname': 'freshrss',
|
|
'user': 'freshrss',
|
|
'password': 'freshrss',
|
|
'host': 'erhe.top',
|
|
'port': '20788'
|
|
}
|
|
|
|
# SQL 查询语句
|
|
query = 'SELECT id, url FROM freshrss_toor_feed;'
|
|
|
|
try:
|
|
# 建立数据库连接
|
|
conn = psycopg2.connect(**db_params)
|
|
|
|
# 创建 cursor 对象
|
|
cur = conn.cursor()
|
|
|
|
# 执行 SQL 查询
|
|
cur.execute(query)
|
|
|
|
# 获取查询结果
|
|
records = cur.fetchall()
|
|
|
|
# 遍历查询结果
|
|
for record in records:
|
|
id, url = record
|
|
|
|
# 替换 rsshub.app 为 rsshub.erhe.top
|
|
if 'rsshub.app' in url:
|
|
url = url.replace('rsshub.app', 'rsshub.erhe.top')
|
|
|
|
# 如果不包含 #force_feed,则在末尾加上
|
|
if '#force_feed' not in url:
|
|
url += '#force_feed'
|
|
|
|
# 更新 SQL 语句
|
|
update_query = 'UPDATE freshrss_toor_feed SET url = %s WHERE id = %s;'
|
|
|
|
# 执行更新操作
|
|
cur.execute(update_query, (url, id))
|
|
|
|
# 提交事务
|
|
conn.commit()
|
|
|
|
print("Data updated successfully.")
|
|
|
|
except psycopg2.Error as e:
|
|
print(f"Database error: {e}")
|
|
conn.rollback()
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
finally:
|
|
# 关闭 cursor 和连接
|
|
if 'cur' in locals():
|
|
cur.close()
|
|
if 'conn' in locals():
|
|
conn.close() |