提交 377b7a10 作者: XveLingKun

微信公众号调整

上级 dc808e12
......@@ -12,6 +12,8 @@ from pymysql.converters import escape_string
import sys
# sys.path.append('D:\\zzsn\\base')
from retry import retry
from base import BaseCore
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
......@@ -167,7 +169,7 @@ def getnumber_redis():
length = r.llen('WeiXinGZH:infoSourceCode')
return length
@retry(tries=2,delay=3)
def insertWxList(dic_url, news_title, url_news, news_date):
selectCountSql = f"select count(1) from wx_link where link='{escape_string(url_news)}'"
cursor_.execute(selectCountSql)
......@@ -183,6 +185,7 @@ def insertWxList(dic_url, news_title, url_news, news_date):
cnx_.commit()
except Exception as e:
log.error(f"保存数据库失败:{e}")
raise
# 查询放入之后的id
selectIdSql = f"select id from wx_link where sid='{dic_url['sid']}' and link='{escape_string(url_news)}'"
cursor_.execute(selectIdSql)
......@@ -192,7 +195,7 @@ def insertWxList(dic_url, news_title, url_news, news_date):
r.ping()
except:
r_ = redis.Redis(host="114.116.90.53", port=6380, password='clbzzsn', db=6)
r_.lpush('WeiXinGZH:url', linkid)
r_.lpush('WeiXinGZH:linkid', linkid)
r.lpush('WeiXinGZH:linkid', linkid)
# 表示插入数据库成功
return 1
......@@ -285,10 +288,15 @@ def spider(dic_url, dic_user_count):
publish_date = time.strftime('%Y-%m-%d %H:%M:%S', publish_date)
if link not in linke_list:
linke_list.append(link)
try:
flgA = insertWxList(dic_url, title, link, publish_date)
if flgA == 0:
flgB = True
break
except:
pass
if flgB:
break
if flgB:
break
if len(linke_list) >= total_count:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论