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.
140 lines
3.0 KiB
140 lines
3.0 KiB
# -*- coding: utf-8 -*-
|
|
|
|
import time
|
|
from playwright.sync_api import sync_playwright
|
|
import psycopg2
|
|
|
|
|
|
def run(playwright):
|
|
browser = playwright.webkit.launch(headless=True)
|
|
|
|
context = browser.new_context()
|
|
|
|
page = context.new_page()
|
|
|
|
page.goto('https://rss.erhe.top/')
|
|
|
|
page.fill('#username', 'toor')
|
|
|
|
page.fill('#passwordPlain', '!QAZ2wsx+0913')
|
|
|
|
page.click('#loginButton')
|
|
|
|
time.sleep(4)
|
|
|
|
try:
|
|
page.goto('https://rss.erhe.top/i/?c=feed&a=actualize')
|
|
title = page.title()
|
|
print(f'{title} 更新成功')
|
|
except Exception as e:
|
|
print(f'更新失败 {str(e)}')
|
|
|
|
time.sleep(1)
|
|
|
|
context.close()
|
|
browser.close()
|
|
print('rss订阅源更新完成')
|
|
|
|
|
|
def check_data_count():
|
|
# 数据库连接参数
|
|
db_params = {
|
|
'dbname': 'freshrss',
|
|
'user': 'freshrss',
|
|
'password': 'freshrss',
|
|
'host': 'erhe.top',
|
|
'port': '20788'
|
|
}
|
|
|
|
# SQL 查询语句
|
|
query = 'SELECT COUNT(*) FROM freshrss_toor_entry;'
|
|
|
|
try:
|
|
# 建立数据库连接
|
|
conn = psycopg2.connect(**db_params)
|
|
|
|
# 创建 cursor 对象
|
|
cur = conn.cursor()
|
|
|
|
# 执行 SQL 查询
|
|
cur.execute(query)
|
|
|
|
# 获取查询结果
|
|
records = cur.fetchall()
|
|
|
|
count_num = records[0][0]
|
|
print(f'\n\nfreshrss_toor_entry 表共有数据数量为: {count_num}')
|
|
|
|
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()
|
|
|
|
|
|
def read_ids():
|
|
ids = []
|
|
# 数据库连接参数
|
|
db_params = {
|
|
'dbname': 'freshrss',
|
|
'user': 'freshrss',
|
|
'password': 'freshrss',
|
|
'host': 'erhe.top',
|
|
'port': '20788'
|
|
}
|
|
|
|
# SQL 查询语句
|
|
query = 'SELECT id, url FROM freshrss_toor_feed order by id ASC;'
|
|
|
|
try:
|
|
# 建立数据库连接
|
|
conn = psycopg2.connect(**db_params)
|
|
|
|
# 创建 cursor 对象
|
|
cur = conn.cursor()
|
|
|
|
# 执行 SQL 查询
|
|
cur.execute(query)
|
|
|
|
# 获取查询结果
|
|
records = cur.fetchall()
|
|
|
|
for record in records:
|
|
id, url = record
|
|
print(id, url)
|
|
ids.append(id)
|
|
|
|
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()
|
|
|
|
if ids:
|
|
return ids
|
|
else:
|
|
return None
|
|
|
|
|
|
if __name__ == '__main__':
|
|
ids = read_ids()
|
|
|
|
if not ids:
|
|
print('未获取到订阅源id, 程序退出')
|
|
exit(0)
|
|
# with sync_playwright() as playwright:
|
|
# run(playwright)
|
|
#
|
|
# check_data_count()
|
|
|