Skip to content

Commit 3dd6ba5

Browse files
authored
Version 4.0
1 parent 1e437ed commit 3dd6ba5

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

ApplSec.py

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import tweepy
44
import requests
55
from datetime import date
6+
from collections import Counter
67
from bs4 import BeautifulSoup, SoupStrainer
78

89
api_key = "x"
@@ -13,30 +14,56 @@
1314
auth = tweepy.OAuthHandler(api_key, api_secret_key)
1415
auth.set_access_token(access_token, access_secret_key)
1516
api = tweepy.API(auth)
16-
api
17+
1718

1819
updatesPage = requests.get("https://support.apple.com/en-us/HT201222").text
1920
currentDateFormatOne = str(date.today().day) + " " + str(date.today().strftime("%B")[0:3]) + " " + str(date.today().year)
2021
currentDateFormatTwo = str(date.today().strftime("%B")) + " " + str(date.today().day) + ", " + str(date.today().year)
2122

22-
2323
newHeader = []
2424
numberCVE = []
25+
countStrong = []
26+
newStrong = []
2527

2628
def getData(link):
2729
for x in link:
2830
newPage = requests.get(x)
2931
soup = BeautifulSoup(newPage.content, "html.parser")
32+
3033
# get the title of the new version
3134
allHeaders = soup.find_all("h2")
32-
newHeader.append(re.sub("<[^>]*?>","", str(allHeaders[1])))
35+
currentHeader = re.sub("<[^>]*?>","", str(allHeaders[1]))
36+
if "macOS" in currentHeader:
37+
# if macOS in the title take only the first part
38+
currentHeader = currentHeader.split(",", 1)[0]
39+
if "iOS" in currentHeader:
40+
# if iOS in the title take only the first part; without iPadOS
41+
currentHeader = currentHeader.split("and", 1)[0].rstrip()
42+
newHeader.append(currentHeader)
43+
3344
# get the number of CVEs on the page
3445
numberCVE.append(len(re.findall("CVE", str(soup))) - 1)
35-
for x in newHeader:
36-
# if there is macOS in the header take only the first part, not the full title
37-
if "macOS" in x:
38-
macosIsHere = newHeader.index(x)
39-
newHeader[macosIsHere] = x.split(",", 1)[0]
46+
47+
# search if there were any zero-day vulnerabilities fixed
48+
number0Days = 0
49+
if link == newLinks:
50+
if "in the wild" or "actively exploited" in soup:
51+
number0Days = len(re.findall("in the wild", str(soup)))
52+
number0Days += len(re.findall("actively exploited", str(soup)))
53+
results0Days3 = ""
54+
if number0Days == 1:
55+
results0Days3 += str(number0Days) + " zero-day vulnerability fixed in " + currentHeader
56+
else:
57+
results0Days3 += str(number0Days) + " zero-day vulnerabilities fixed in " + currentHeader
58+
59+
if number0Days >= 1:
60+
if len(re.findall("zero-day", results0Days3)) == 1:
61+
results0Days2 = ":mega: EMERGENCY UPDATE :mega:\n\n"
62+
else:
63+
results0Days2 = ":mega: EMERGENCY UPDATES :mega:\n\n"
64+
results0Days1 = results0Days2 + results0Days3
65+
66+
api.update_status(emoji.emojize("{}".format(results0Days1), use_aliases=True))
4067

4168

4269
allLinks = []
@@ -50,11 +77,26 @@ def getData(link):
5077
# get only the new links from the page
5178
newLinks = allLinks[22:len(re.findall(currentDateFormatOne, updatesPage)) + 22]
5279
getData(newLinks)
53-
# print results
54-
results = ":closed_lock_with_key: NEW UPDATES RELEASED :closed_lock_with_key:\n\n"
80+
81+
# api.update_status results
82+
if len(newHeader) == 1:
83+
results = ":collision: NEW UPDATE RELEASED :collision:\n\n"
84+
else:
85+
results = ":collision: NEW UPDATES RELEASED :collision:\n\n"
86+
5587
for x in newHeader:
56-
results += "• " + x + " released with " + str(numberCVE[0]) + " security fixes\n"
88+
if "iOS" in x:
89+
results += ":iphone: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
90+
elif "watchOS" in x:
91+
results += ":watch: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
92+
elif "tvOS" in x:
93+
results += ":tv: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
94+
elif "macOS" in x:
95+
results += ":computer: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
96+
else:
97+
results += ":hammer_and_wrench: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
5798
numberCVE.pop(0)
99+
58100
api.update_status(emoji.emojize("{}".format(results), use_aliases=True))
59101

60102

@@ -63,15 +105,32 @@ def getData(link):
63105
# check if the last 20 update pages got any changes today
64106
page = requests.get(x).text
65107
search = "Entry added " + str(currentDateFormatTwo)
108+
66109
if search in page:
67110
updatedLinks.append(x)
68111

69112
if updatedLinks != []:
113+
# if any security notes were updated
70114
newHeader.clear()
71115
getData(updatedLinks)
72-
# print results
73-
results = "UPDATED TODAY:\n"
116+
117+
# api.update_status results
118+
if len(newHeader) == 1:
119+
results = ":arrows_counterclockwise: " + str(len(updatedLinks)) + " SECURITY NOTE UPDATED :arrows_counterclockwise:\n\n"
120+
else:
121+
results = ":arrows_counterclockwise: " + str(len(updatedLinks)) + " SECURITY NOTES UPDATED :arrows_counterclockwise:\n\n"
122+
74123
for x in newHeader:
75-
results += x + " was released " + str(numberCVE[0]) + " security fixes\n"
124+
if "iOS" in x:
125+
results += ":iphone: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
126+
elif "watchOS" in x:
127+
results += ":watch: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
128+
elif "tvOS" in x:
129+
results += ":tv: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
130+
elif "macOS" in x:
131+
results += ":computer: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
132+
else:
133+
results += ":hammer_and_wrench: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n"
76134
numberCVE.pop(0)
77-
api.update_status(emoji.emojize(results))
135+
136+
api.update_status(emoji.emojize("{}".format(results), use_aliases=True))

0 commit comments

Comments
 (0)