|
|
@ -17,7 +17,6 @@ import requests
|
|
|
|
from Util.PostgreSQLUtil import init_postgres_pool
|
|
|
|
from Util.PostgreSQLUtil import init_postgres_pool
|
|
|
|
from Util.WxGzhUtil import init_wechat_browser, get_article_content
|
|
|
|
from Util.WxGzhUtil import init_wechat_browser, get_article_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 在程序开始时添加以下配置
|
|
|
|
# 在程序开始时添加以下配置
|
|
|
|
logging.basicConfig(
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO, # 设置日志级别为INFO
|
|
|
|
level=logging.INFO, # 设置日志级别为INFO
|
|
|
@ -31,6 +30,7 @@ handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
|
|
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
|
|
logger.addHandler(handler)
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_wechat_sources():
|
|
|
|
async def get_wechat_sources():
|
|
|
|
"""从t_wechat_source表获取微信公众号列表"""
|
|
|
|
"""从t_wechat_source表获取微信公众号列表"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -65,9 +65,10 @@ async def is_article_exist(pool, article_url):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
async with pool.acquire() as conn:
|
|
|
|
async with pool.acquire() as conn:
|
|
|
|
row = await conn.fetchrow('''
|
|
|
|
row = await conn.fetchrow('''
|
|
|
|
SELECT 1 FROM t_wechat_articles
|
|
|
|
SELECT 1
|
|
|
|
WHERE url = $1 LIMIT 1
|
|
|
|
FROM t_wechat_articles
|
|
|
|
''', article_url)
|
|
|
|
WHERE url = $1 LIMIT 1
|
|
|
|
|
|
|
|
''', article_url)
|
|
|
|
return row is not None
|
|
|
|
return row is not None
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logging.error(f"检查文章存在性失败: {e}")
|
|
|
|
logging.error(f"检查文章存在性失败: {e}")
|
|
|
@ -79,15 +80,15 @@ async def save_article_to_db(pool, article_title, account_name, article_url, pub
|
|
|
|
if await is_article_exist(pool, article_url):
|
|
|
|
if await is_article_exist(pool, article_url):
|
|
|
|
logging.info(f"文章已存在,跳过保存: {article_url}")
|
|
|
|
logging.info(f"文章已存在,跳过保存: {article_url}")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
async with pool.acquire() as conn:
|
|
|
|
async with pool.acquire() as conn:
|
|
|
|
await conn.execute('''
|
|
|
|
await conn.execute('''
|
|
|
|
INSERT INTO t_wechat_articles
|
|
|
|
INSERT INTO t_wechat_articles
|
|
|
|
(title, source, url, publish_time, content, source_id)
|
|
|
|
(title, source, url, publish_time, content, source_id)
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
|
|
''', article_title, account_name, article_url,
|
|
|
|
''', article_title, account_name, article_url,
|
|
|
|
publish_time, content, id)
|
|
|
|
publish_time, content, id)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logging.error(f"保存文章失败: {e}")
|
|
|
|
logging.error(f"保存文章失败: {e}")
|
|
|
|
|
|
|
|
|
|
|
@ -105,7 +106,7 @@ if __name__ == '__main__':
|
|
|
|
# 换算出过期时间
|
|
|
|
# 换算出过期时间
|
|
|
|
expiry_time = time.localtime(expiry)
|
|
|
|
expiry_time = time.localtime(expiry)
|
|
|
|
expiry_date = time.strftime("%Y-%m-%d %H:%M:%S", expiry_time)
|
|
|
|
expiry_date = time.strftime("%Y-%m-%d %H:%M:%S", expiry_time)
|
|
|
|
logger.info("cookies的过期时间一般是4天,cookies过期时间:", expiry_date)
|
|
|
|
logger.info(f"cookies的过期时间一般是4天,cookies过期时间:%s" % expiry_date)
|
|
|
|
# 获取当前时间戳
|
|
|
|
# 获取当前时间戳
|
|
|
|
current_timestamp = time.time()
|
|
|
|
current_timestamp = time.time()
|
|
|
|
# 检查是否已过期
|
|
|
|
# 检查是否已过期
|
|
|
|