3
3
import tweepy
4
4
import requests
5
5
from datetime import date
6
+ from collections import Counter
6
7
from bs4 import BeautifulSoup , SoupStrainer
7
8
8
9
api_key = "x"
13
14
auth = tweepy .OAuthHandler (api_key , api_secret_key )
14
15
auth .set_access_token (access_token , access_secret_key )
15
16
api = tweepy .API (auth )
16
- api
17
+
17
18
18
19
updatesPage = requests .get ("https://support.apple.com/en-us/HT201222" ).text
19
20
currentDateFormatOne = str (date .today ().day ) + " " + str (date .today ().strftime ("%B" )[0 :3 ]) + " " + str (date .today ().year )
20
21
currentDateFormatTwo = str (date .today ().strftime ("%B" )) + " " + str (date .today ().day ) + ", " + str (date .today ().year )
21
22
22
-
23
23
newHeader = []
24
24
numberCVE = []
25
+ countStrong = []
26
+ newStrong = []
25
27
26
28
def getData (link ):
27
29
for x in link :
28
30
newPage = requests .get (x )
29
31
soup = BeautifulSoup (newPage .content , "html.parser" )
32
+
30
33
# get the title of the new version
31
34
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
+
33
44
# get the number of CVEs on the page
34
45
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 ))
40
67
41
68
42
69
allLinks = []
@@ -50,11 +77,26 @@ def getData(link):
50
77
# get only the new links from the page
51
78
newLinks = allLinks [22 :len (re .findall (currentDateFormatOne , updatesPage )) + 22 ]
52
79
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
+
55
87
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 "
57
98
numberCVE .pop (0 )
99
+
58
100
api .update_status (emoji .emojize ("{}" .format (results ), use_aliases = True ))
59
101
60
102
@@ -63,15 +105,32 @@ def getData(link):
63
105
# check if the last 20 update pages got any changes today
64
106
page = requests .get (x ).text
65
107
search = "Entry added " + str (currentDateFormatTwo )
108
+
66
109
if search in page :
67
110
updatedLinks .append (x )
68
111
69
112
if updatedLinks != []:
113
+ # if any security notes were updated
70
114
newHeader .clear ()
71
115
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
+
74
123
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 "
76
134
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