-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutils.py
60 lines (50 loc) · 1.68 KB
/
utils.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
59
60
import copy
import pprint
from colorama import Fore
class Color:
@staticmethod
def print_focus(data: str):
print(Fore.YELLOW+data+Fore.RESET)
@staticmethod
def print_success(data: str):
print(Fore.LIGHTGREEN_EX+data+Fore.RESET)
@staticmethod
def print_failed(data: str):
print(Fore.LIGHTRED_EX+data+Fore.RESET)
@staticmethod
def print(data):
pprint.pprint(data)
class Readme:
@staticmethod
def get_dalao_top(dalao: dict, num: int) -> list({str, dict}):
"""取出top大佬"""
dalao_top = sorted(list(dalao.items()), key=lambda r: len(r[1]['cve']), reverse=True)
return dalao_top[:num]
@staticmethod
def make_table(dalao: list):
"""Markdown表格"""
content = ''
for idx, (name, value) in enumerate(dalao):
if value['url']:
content += f'| {idx+1} | [{name}]({value["url"]}) | {len(value["cve"])} |\n'
else:
content += f'| {idx+1} | {name} | {len(value["cve"])} |\n'
return content
@staticmethod
def get_first_year(dalao: dict) -> int:
"""找到最早的年份"""
cve = []
for v in dalao.values():
cve += v['cve']
first_year = sorted(cve)[0].split('-')[1]
return int(first_year)
@staticmethod
def get_year_dalao(dalao: dict, year: int) -> dict:
"""取出年度大佬"""
temp = copy.deepcopy(dalao)
for v in list(temp.items()):
if new_cve := [cve for cve in v[1]['cve'] if cve.startswith(f'CVE-{year}')]:
temp[v[0]]['cve'] = new_cve
else:
temp.pop(v[0])
return temp