-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_tool.py
More file actions
99 lines (78 loc) · 3.12 KB
/
github_tool.py
File metadata and controls
99 lines (78 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#_*_ coding: utf-8 _*_
import requests
import json
import time
header = {}
def Request(api, key):
return requests.get(api.format(key),verify=False).text
def getTotal(api, key):
content = json.loads(Request(api, key))
return int(content["total_count"])
def getInfo(api, key, index, send_count):
content = json.loads(Request(api, key))
for i in range(send_count):
info_list[index][str(i)] = {
"name": content["items"][i]["name"],
"description": content["items"][i]["description"],
"url": content["items"][i]["html_url"]
}
# 初始化,获取初始count
def Init(api, key_words):
for index in range(len(key_words)):
time.sleep(20)
key = key_words[index]
info_list[index]["key word"] = key
info_list[index]["flag_total"] = getTotal(api, key)
# 判断count后将信息存到列表中
def Update(api, key_words):
for index in range(len(key_words)):
time.sleep(20)
key = key_words[index]
total = getTotal(api, key)
if info_list[index]["flag_total"] < total:
send_count = total - info_list[index]["flag_total"]
info_list[index]["flag_total"] = total # update
getInfo(api, key, index, send_count)
# 发送到Server酱
def Send(info_list, key):
url = 'https://sc.ftqq.com/{}.send'.format(key)
for i in range(len(info_list)):
title = "Github监控更新提醒:{}".format(info_list[i]["key word"])
desp = ""
if "name" in str(info_list[i]):
count = len(info_list[i]) - 2
for k in range(count):
desp += "名称:{}\n\n简介:{}\n\n地址:{}\n\n".format(info_list[i][str(k)]["name"], info_list[i][str(k)]["description"], info_list[i][str(k)]["url"])
del(info_list[i][str(k)])
data = {
"text": title,
"desp": desp
}
res = requests.post(url, data=data,verify=False)
if __name__ == '__main__':
print("initial... " + time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
api = 'https://api.github.com/search/repositories?q={}&sort=updated'
# set your config
config = {
"key_words": ['CVE-2020', 'password'], #监控的关键词,可多个监控
"intval": 100, # 发送间隔, 单位为s;
"SCKEY": 'you key', # Server酱 KEY
}
info_list = []
for i in range(len(config["key_words"])):
info_list.append({})
Init(api, config["key_words"])
while 1:
try:
print("waiting to update... " + time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
time.sleep(config["intval"])
Update(api, config["key_words"])
print(info_list) # 控制台打印信息
Send(info_list, config["SCKEY"]) # 推送信息到微信
except:
print("Connection refused by the server..")
print("Let me sleep for 5 seconds")
print("ZZZzzz...")
time.sleep(5)
print("Was a nice slepp ,now let me continue...")
continue