Last active
February 27, 2019 20:42
-
-
Save jeffehobbs/cedf9dab633918510e00ae997bc30cfc to your computer and use it in GitHub Desktop.
Checks for new versions of ChromeOS, sends an email if they exist. Python 2.7, requires Sparkpost API key and client library to be installed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # os-check.py // jeffhobbs@gmail.com | |
| # check chromeOS site for specific updates | |
| import csv, urllib2 | |
| from sparkpost import SparkPost | |
| # customize the list of devices, email addresses, and add your own SparkPost API key | |
| # if you want to be alerted on minor point releases, change "False" to "True" | |
| devices = ['eve','panther'] | |
| email_to = 'your_email_here@domain.com' | |
| email_from = 'address_to_send_from@domain.com' | |
| sparkpost_api_key = 'get_yours_at_sparkpost_dot_com' | |
| alert_on_minor_updates = False | |
| url = 'https://cros-updates-serving.appspot.com/csv' | |
| # read last version numbers | |
| def read_version_number(device): | |
| f = open(device + '.txt','r') | |
| version = f.read() | |
| f.close() | |
| return version | |
| # save current version numbers | |
| def save_version_number(device,version): | |
| f = open(device + '.txt','w') | |
| f.write(version) | |
| f.close() | |
| # send off an email | |
| def send_email_sparkpost(to,subject,body): | |
| sp = SparkPost(sparkpost_api_key) | |
| response = sp.transmissions.send( | |
| recipients=[to], | |
| html=body, | |
| text=body, | |
| from_email= '🤖 OS CHECK<' + email_from + '>', | |
| track_clicks=False, | |
| subject=subject | |
| ) | |
| print "SENDING EMAIL..." | |
| # main function | |
| if __name__ == '__main__': | |
| response = urllib2.urlopen(url) | |
| cr = csv.reader(response) | |
| for row in cr: | |
| if (row[0] in devices): | |
| device = row[0] | |
| version = row[2] | |
| if not (alert_on_minor_updates): | |
| version = version.split('.', 1)[0] | |
| lastCheckedVersion = read_version_number(device) | |
| if (version > lastCheckedVersion): | |
| message = "New ChromeOS detected for " + device + ": " + version | |
| print message | |
| send_email_sparkpost(email_to,"New ChromeOS detected", message) | |
| else: | |
| print (device + ": " + version) | |
| save_version_number(device,version) | |
| # fin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment