|
@@ -0,0 +1,88 @@
|
|
|
|
|
+# -*- 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)
|
|
|
|
|
+
|
|
|
|
|
+ for i in range(1, 300):
|
|
|
|
|
+ try:
|
|
|
|
|
+ page.goto(f'https://rss.erhe.top/i/?c=feed&a=actualize&id={i}')
|
|
|
|
|
+ title = page.title()
|
|
|
|
|
+ if '首页' in title:
|
|
|
|
|
+ continue
|
|
|
|
|
+ print(f'{title} 更新成功')
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(f'{i} 更新失败')
|
|
|
|
|
+
|
|
|
|
|
+ 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()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
|
+ with sync_playwright() as playwright:
|
|
|
|
|
+ run(playwright)
|
|
|
|
|
+
|
|
|
|
|
+ check_data_count()
|