-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyfetch.py
58 lines (49 loc) · 1.66 KB
/
pyfetch.py
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
#!/bin/python
import json
import requests
import sys
def get_cve(url):
# Get request
req = requests.get(url)
req.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0'
# JSON unmarshalling
result = json.loads(req.text)
data = result['data']
for value in data:
print(value['cve'])
def get_cve_info(url):
# Get request
req = requests.get(url)
req.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0'
# JSON unmarshalling
result = json.loads(req.text)
data = result['data']
for value in data:
cve = value['cve']
cve_info = value['description']
cve_severity = value['severity']
print(f"{cve}\nDescription: {cve_info}\nSeverity: {cve_severity}")
print("-----------------------------------")
def main():
if len(sys.argv) < 2:
print('Usage: pyfetch day|week [-info]')
return
elif sys.argv[1] == 'day':
if len(sys.argv) == 3 and sys.argv[2] == '-info':
url = 'https://cvetrends.com/api/cves/24hrs'
get_cve_info(url)
else:
url = 'https://cvetrends.com/api/cves/24hrs'
get_cve(url)
elif sys.argv[1] == 'week':
if len(sys.argv) == 3 and sys.argv[2] == '-info':
url = 'https://cvetrends.com/api/cves/order-by-tweets-7days'
get_cve_info(url)
else:
url = 'https://cvetrends.com/api/cves/order-by-tweets-7days'
get_cve(url)
else:
print('Usage: pyfetch day|week [-info]')
return
if __name__ == '__main__':
main()