-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths8_updates.py
executable file
·55 lines (45 loc) · 1.48 KB
/
s8_updates.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
#!/usr/bin/env python3
import requests
import smtplib
import datetime
import config
resp = requests.get(config.url)
content = resp.content.decode('utf-8')
def get_update(response, page_content):
if response.status_code == 200:
for line in page_content.splitlines():
if config.date in line:
update = line[65:-63]
return update
def compare_updates(new, old=config.versions):
if new == old:
print('\n{}: No changes detected.'.format(datetime.datetime.now()))
pass
else:
print('\n{}: Changes detected.'.format(datetime.datetime.now()))
return True
def send_email(message):
try:
server = smtplib.SMTP_SSL(host=config.smtp_srv, port=465)
server.ehlo()
server.login(user=config.from_email, password=config.as_passwd)
server.sendmail(from_addr=config.from_email, to_addrs=config.to_email, msg=message)
server.close()
print('\nEmail sent!')
except KeyboardInterrupt as eki:
print('\nReceived CTRL+C.\nExiting...')
except Exception as e:
print('\nError during send_email()...')
print(e)
def main():
latest_update = get_update(resp, content)
if compare_updates(latest_update) == True:
send_email(config.mesg)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt as eki:
print('\nReceived CTRL+C.\nExiting...')
except Exception as e:
print('Error during main().')
print(e)