Merge pull request #8 from wuyoukm/master

细化更新
This commit is contained in:
yhy 2021-07-30 16:54:58 +08:00 committed by GitHub
commit dbe5790593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@
# https://my.oschina.net/u/4581868/blog/4380482 # https://my.oschina.net/u/4581868/blog/4380482
# https://github.com/kiang70/Github-Monitor # https://github.com/kiang70/Github-Monitor
import json
import requests, time, re import requests, time, re
import dingtalkchatbot.chatbot as cb import dingtalkchatbot.chatbot as cb
@ -15,11 +16,11 @@ import hashlib
from lxml import etree from lxml import etree
import traceback import traceback
github_headers = { github_headers = {
'Authorization': "token xxxxxx" # 替换自己的github token https://github.com/settings/tokens/new 'Authorization': "token xxxxxx" # 替换自己的github token https://github.com/settings/tokens/new
} }
# 抓取本年cve # 抓取本年cve
def getNews(): def getNews():
try: try:
@ -36,6 +37,7 @@ def getNews():
print(e, "github链接不通") print(e, "github链接不通")
return '', '', '' return '', '', ''
# 通过 pushed_at 检查工具是否更新 # 通过 pushed_at 检查工具是否更新
def get_pushed_at_time(tools_list): def get_pushed_at_time(tools_list):
total_list = [] total_list = []
@ -45,15 +47,20 @@ def get_pushed_at_time(tools_list):
return total_list return total_list
def get_update_log(url): def get_update_log(url):
# 考虑到有的工具没有 releases, 则通过 commits 记录获取更新描述 # 考虑到有的工具没有 releases, 则通过 commits 记录获取更新描述
# 判断是否有 releases 记录 # 判断是否有 releases 记录
json_str = requests.get(url + '/releases', headers=github_headers, timeout=10).json() json_str = requests.get(url + '/releases', headers=github_headers, timeout=10).json()
if len(json_str) != 0: if len(json_str) != 0:
try:
update_log = json_str[0]['body'] update_log = json_str[0]['body']
except Exception as e:
update_log = "作者未写更新内容"
download_url = json_str[0]['html_url'] download_url = json_str[0]['html_url']
return update_log, download_url tools_version = json_str[0]['name']
return update_log, download_url,len(json_str),tools_version
else: else:
json_str = requests.get(url + '/commits', headers=github_headers, timeout=10).json() json_str = requests.get(url + '/commits', headers=github_headers, timeout=10).json()
update_log = json_str[0]['commit']['message'] update_log = json_str[0]['commit']['message']
@ -69,6 +76,7 @@ def nmd5(str):
str_md5 = m.hexdigest() str_md5 = m.hexdigest()
return str_md5 return str_md5
# 有道翻译 # 有道翻译
def translate(word): def translate(word):
headerstr = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36' headerstr = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'
@ -130,12 +138,14 @@ def dingding(text, msg):
ding = cb.DingtalkChatbot(webhook, secret=secretKey) ding = cb.DingtalkChatbot(webhook, secret=secretKey)
ding.send_text(msg='{}\r\n{}'.format(text, msg), is_at_all=False) ding.send_text(msg='{}\r\n{}'.format(text, msg), is_at_all=False)
# server酱 http://sc.ftqq.com/?c=code # server酱 http://sc.ftqq.com/?c=code
def server(text, msg): def server(text, msg):
# 将 xxxx 换成自己的server SCKEY # 将 xxxx 换成自己的server SCKEY
uri = 'https://sc.ftqq.com/xxxx.send?text={}&desp={}'.format(text, msg) uri = 'https://sc.ftqq.com/xxxx.send?text={}&desp={}'.format(text, msg)
requests.get(uri, headers=github_headers, timeout=10) requests.get(uri, headers=github_headers, timeout=10)
# 添加Telegram Bot推送支持 # 添加Telegram Bot推送支持
def tgbot(text, msg): def tgbot(text, msg):
import telegram import telegram
@ -162,6 +172,7 @@ def get_cve_des_zh(cve):
des = html.xpath('//*[@id="GeneratedTable"]/table//tr[4]/td/text()')[0].strip() des = html.xpath('//*[@id="GeneratedTable"]/table//tr[4]/td/text()')[0].strip()
return translate(des) return translate(des)
def sendNews(tools_list): def sendNews(tools_list):
while True: while True:
try: try:
@ -185,9 +196,9 @@ def sendNews(tools_list):
# 推送标题 # 推送标题
text = r'有新的CVE送达' text = r'有新的CVE送达'
# 获取 cve 名字 根据cve 名字,获取描述,并翻译 # 获取 cve 名字 根据cve 名字,获取描述,并翻译
cve_name = re.findall("(?i)CVE\-\d+\-\d+", req['items'][0]['name'])[0].upper() cve_name = re.findall('(CVE\-\d+\-\d+)', req['items'][0]['name'])[0].upper()
cve_zh = get_cve_des_zh(cve_name) cve_zh = get_cve_des_zh(cve_name)
msg = "CVE编号"+ cve_name + "\r\n"+"Github地址"+ str(getNews()[2]) + "\r\n" + "CVE描述"+ cve_zh msg = "CVE编号" + cve_name + "\r\n" + "Github地址" + str(getNews()[2]) + "\r\n" + "CVE描述" +"\r\n"+ cve_zh
# 三选一即可,没配置的 注释或者删掉 # 三选一即可,没配置的 注释或者删掉
# server(text, msg) # server(text, msg)
@ -200,15 +211,55 @@ def sendNews(tools_list):
for i in range(len(tools_list)): for i in range(len(tools_list)):
# 两次时间不相等,则代表工具更新 # 两次时间不相等,则代表工具更新
if time_list1[i] != time_list2[i]: if time_list1[i] != time_list2[i]:
update_log, download_url = get_update_log(tools_list[i]) # get_update_log_info = get_update_log(tools_list[i])
if len(get_update_log(tools_list[i])) == 2:
update_log = get_update_log(tools_list[i])[0]
download_url = get_update_log(tools_list[i])[1]
tools_name = tools_list[i].split('/')[-1] tools_name = tools_list[i].split('/')[-1]
text = r'** ' + tools_name + r' ** 工具更新啦!' text = r'** ' + tools_name + r' ** 工具更新啦!'
body = "工具名称:" + tools_name + "\r\n" + "工具地址:" + download_url + "\r\n" + "工具更新日志:" + update_log body = "工具名称:" + tools_name + "\r\n" + "工具地址:" + download_url + "\r\n" + "工具更新日志:" + "\r\n" + update_log
# 三选一即可,没配置的 注释或者删掉 # 三选一即可,没配置的 注释或者删掉
# server(text, body) # server(text, body)
dingding(text, body) dingding(text, body)
# tgbot(text,body) # tgbot(text,body)
print(body) print(body)
elif len(get_update_log(tools_list[i])) == 4:
one_all_info = get_update_log(tools_list[i])
release_len_one = one_all_info[2]
time.sleep(120)
two_all_info = get_update_log(tools_list[i])
release_len_two = two_all_info[2]
if release_len_one != release_len_two:
update_log = two_all_info[0]
download_url = two_all_info[1]
tools_version = two_all_info[3]
tools_name = tools_list[i].split('/')[-1]
text = r'** ' + tools_name + r' ** 工具版本更新啦!'
body = "工具名称:" + tools_name + "\r\n"+"当前最新版本:"+tools_version+"\r\n"+ "工具下载地址:" + download_url + "\r\n" + "工具更新日志:" + "\r\n" + update_log
# 三选一即可,没配置的 注释或者删掉
# server(text, body)
dingding(text, body)
# tgbot(text,body)
else:
commits_url = tools_list[i]+"/commits"
commits_url_response_json = requests.get(commits_url).text
commits_json = json.loads(commits_url_response_json)
tools_name = tools_list[i].split('/')[-1]
download_url = commits_json[0]['html_url']
try:
update_log = commits_json[0]['commit']['message']
except Exception as e:
update_log = "作者未写更新内容具体点击更新详情地址的URL进行查看"
text = r'** ' + tools_name + r' ** 工具小更新了一波!'
body = "工具名称:" + tools_name + "\r\n" + "更新详情地址:" + download_url + "\r\n" + "工具更新日志:" + "\r\n" + update_log
# 三选一即可,没配置的 注释或者删掉
# server(text, body)
dingding(text, body)
# tgbot(text,body)
except Exception as e: except Exception as e:
print("Program runing error:{}".format(traceback.print_exc())) print("Program runing error:{}".format(traceback.print_exc()))