Permalink
Browse files

converted to google apps script

  • Loading branch information...
1 parent 5689547 commit 4b1ba3faad599ad582830ce8a2711a7e6bb0e7b1 @yaph committed May 23, 2013
Showing with 35 additions and 37 deletions.
  1. +0 −1 .gitignore
  2. +15 −4 LICENSE
  3. +4 −0 README.md
  4. +16 −0 sitemonitor.gs
  5. +0 −32 sitemonitor.py
View
1 .gitignore
@@ -2,4 +2,3 @@
MANIFEST
build/
dist/
-logya.egg-info
View
19 LICENSE
@@ -1,7 +1,18 @@
-Copyright (C) 2012 by Ramiro Gómez (http://www.ramiro.org/)
+Copyright (C) 2013 by Ramiro Gómez (http://ramiro.org/)
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
4 README.md
@@ -0,0 +1,4 @@
+Google Apps Script Site Monitor
+
+Read the article [Quick and Dirty Site Monitoring with Google Apps Script](http://geeksta.net/geeklog/quick-dirty-site-monitoring-google-apps-script/)
+to learn how to use this script to monitor Web sites listed in a Google Docs spreadsheet.
View
16 sitemonitor.gs
@@ -0,0 +1,16 @@
+function checkURLs() {
+ var errors = [];
+ var ss = SpreadsheetApp.getActiveSpreadsheet();
+ var rows = ss.getDataRange().getValues();
+ for (i in rows) {
+ var url = rows[i][0];
+ var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
+ var status = response.getResponseCode();
+ if (status !== 200)
+ errors.push(status + ' - '+ url);
+ }
+ if (errors.length) {
+ var emailTo = Session.getActiveUser().getEmail();
+ MailApp.sendEmail(emailTo, 'Sitemonitor Status', errors.join('\n'));
+ }
+}
View
32 sitemonitor.py
@@ -1,32 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-import argparse
-import requests
-
-__version__ = '0.1'
-
-def geturls():
- return ['http://www.google.com/']
-
-
-def checkurls(args):
- print args.email, args.file
- errors = []
- urls = geturls()
- for url in urls:
- r = requests.head(url)
- if 200 != r.status_code:
- errors.append((r.status_code, url))
-
-
-def main():
- parser = argparse.ArgumentParser(description='Monitor availability of websites.', version=__version__)
- parser.add_argument('--file', required=True, help='File with newline separated urls.')
- parser.add_argument('--email', required=True, help='Email address to deliver error report.')
- parser.set_defaults(func=checkurls)
- args = parser.parse_args()
- args.func(args)
-
-
-if __name__ == "__main__":
- main()

0 comments on commit 4b1ba3f

Please sign in to comment.