Python 3 Script/Project
-
As a means of getting better acquainted with Python 3 I've decided to create a script that does a bit of web scraping on http://www.google.com/appsstatus#hl=en&v=status and informs me when the state of any particular Google App is less than peachy(or not green to be exact).
I figure I would run this on a 15 minute interval and have it inform me via email if any of the services that we use have a status other than green, with the exception of gmail (because emailing me when I don't have email would be kinda pointless...); in that case I would have it send me a SMS.
Does this seem like a reasonable use for Python? Is there an API I'm overlooking that I could use instead of scraping?
Looking for opinions and/or criticism.
---Added Github Repo---
Github: https://github.com/ramblingbiped/google-apps-status
import smtplib from selenium import webdriver import time driver = webdriver.PhantomJS() driver.get("http://www.google.com/appsstatus#hl=en&v=status") time.sleep(1) # Dictionary referencing each service's row position within the table displaying their current status app_services = { 'Gmail' : 2, 'Calendar' : 3, 'Messenger' : 4, 'Drive' : 5, 'Docs' : 6, 'Sheets' : 7, 'Slides' : 8, 'Drawings' : 9, 'Sites' : 10, 'Groups' : 11, 'Admin console' : 12, 'Postini' : 13, 'Hangouts' : 14, 'Vault' : 15 } for key, value in app_services.items(): service_name = driver.find_element_by_xpath('//table/tbody/tr[%d]/td[2]' % value).text service_status = driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[3]/table/tbody/tr[%d]/td[1]/span' % value).get_attribute('class') #Check the status of services, if not "green" send notification email. if service_status != 'aad-green-circle': content = 'There is currently a problem with %s!\n\nCheck http://www.google.com/appsstatus for further information directly relevant to the outage.\n' % service_name subject = '%s Service Interruption' % service_name message = 'Subject: %s\n\n%s' % (subject, content) #Credentials of the account authenticating with Google's SMTP server email = '[email protected]' password = 'app-password' #Person to be notified of service outage/downtime sender_address = '[email protected]' recipient_address = '[email protected]' mail = smtplib.SMTP('smtp.gmail.com',587) mail.ehlo() mail.starttls() mail.login(email,password) mail.sendmail(sender_address, recipient_address, message) mail.close() driver.close()
-
Don't know if Google has an API for that, but Python is a great tool for that job.
-
That is pretty cool and I don't think they do have an API for that, a friend mine also had to result to scraping to solve the same problem, though be careful and maybe slightly randomise the interval, they briefly banned him a while back -- everything he did on Google required a CAPTCHA.
-
Yeah, I might back off on the interval and maybe only check every hour or so. I'd like to have something that could eventually proactively notify my users if there are issues with any of the services, and then subsequently notify them when things are back to normal. This would save several emails/messages and my time in actively monitoring problems until things are resolved.
-
I've got the basic scraping all worked out, I'm just at the point that I need to polish and build in the notifications via email and/or sms. Once I'm done I'll go ahead and link everything via github for helpful criticisms and generally rude and inappropriate commentary.
-
Github repo created: https://github.com/ramblingbiped/google-apps-status
-
And done... I added email notification via the smtplib library using Google's SMTP server. I set up a Google App Password for my account to allow authentication of the script without embedding my own credentials, as well as bypassing multi-factor authentication requirements.
Use just requires supplying your own credentials to the "email' and 'password' variables, as well as a sender and recipient address within the script.
-
@RamblingBiped said:
Github repo created: https://github.com/ramblingbiped/google-apps-status
Looks good.