-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
108 lines (77 loc) · 3.01 KB
/
functions.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
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
100
101
102
103
104
105
106
107
108
import re
from datetime import datetime, timedelta
def checkDateFormat(dateFullString):
if dateFullString is None:
return None
# regex to get the date from the string in the format of YYYY-MM-DD or YYYY/MM/DD or YYYY.MM.DD
dateRegex = re.compile(r'^(19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$')
# if the date is not in the correct format return None
if dateRegex.search(dateFullString) is None:
return None
return dateRegex.search(dateFullString).group()
def checkDateRange(startDate, endDate):
if startDate is None or endDate is None:
return False
# remove T00:00:00.000 from the date
startDate = startDate.split("T")[0]
endDate = endDate.split("T")[0]
# convertir les dates en datetime
startDate = datetime.strptime(startDate, '%Y-%m-%d').date()
endDate = datetime.strptime(endDate, '%Y-%m-%d').date()
# calculer la différence entre les deux dates
diff = endDate - startDate
# si la différence est supérieure à 90 jours retourner false
if diff.days > 120:
return splitDate(startDate, endDate)
else:
datesList = [startDate, endDate]
for i in range(1, len(datesList), 2):
print("start date = " + datesList[i - 1].strftime("%Y-%m-%d") + " to endDate " + datesList[i].strftime(
"%Y-%m-%d"))
return datesList
def splitDate(startDate, endDate):
if startDate is None or endDate is None:
return False
datesList = [startDate]
while startDate < endDate:
startDate += timedelta(days=120)
if startDate > endDate:
datesList.append(endDate)
break
datesList.append(startDate)
startDate += timedelta(days=1)
datesList.append(startDate)
for i in range(1, len(datesList), 2):
print("start date = " + datesList[i-1].strftime("%Y-%m-%d") + " to endDate " + datesList[i].strftime("%Y-%m-%d"))
return datesList
def refactorDateFormat(dateFullString):
# replace the / . with -
dateFullString = dateFullString.replace("/", "-")
dateFullString = dateFullString.replace(".", "-")
dateFullString = dateFullString.replace(" ", "-")
return dateFullString + "T00:00:00.000"
def checkDateOrder(startDate, endDate):
if startDate is None or endDate is None:
return False
if startDate > endDate:
return False
return True
def identifyWichAPICall(args):
if args.keyword is not None:
return "keyword"
elif args.vendor is not None or args.product is not None:
return "vendorProduct"
else:
return "all"
def createVirtualMatchString(vendor, product):
if vendor is None and product is None:
return None
if vendor is None:
vendor = "*"
if product is None:
product = "*"
return "cpe:2.3:*:" + vendor + ":" + product + ":*:*:*:*:*:*:*"
def printAllCveObjects(cveList):
for i in range(len(cveList)):
cveList[i].showAll()
print("\n" + "Total number of CVEs: " + str(len(cveList)))