aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-11-20 12:06:17 +0200
committerFilipp Lepalaan <filipp@mac.com>2015-11-20 12:06:17 +0200
commitc8d62061cd8cef78e8b0722e40370dae17df109f (patch)
tree1cdd30345f3391254406d3f91b2aafed1f6ff765
downloaddelta-c8d62061cd8cef78e8b0722e40370dae17df109f.tar.gz
delta-c8d62061cd8cef78e8b0722e40370dae17df109f.tar.bz2
delta-c8d62061cd8cef78e8b0722e40370dae17df109f.zip
Initial commitHEADmaster
-rw-r--r--README.md36
-rwxr-xr-xdelta.py35
-rw-r--r--requirements.txt2
3 files changed, 73 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..cde520b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,36 @@
+### Introduction
+
+This script will return 0 if a web page has changed. It tries to focus on the content parts of the page (using html2text) which might not be appropriate for all cases. Mainly it's useful for monitoring fairly static pages that don't provide RSS feeds. :-)
+
+
+### Installation
+
+ $ pip install -U -r requirements.txt
+
+
+### Usage
+
+ $ delta.py http://example.com/somepage.html
+
+
+### License
+
+Copyright (c) 2015 Filipp Lepalaan
+
+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 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.
diff --git a/delta.py b/delta.py
new file mode 100755
index 0000000..c47f466
--- /dev/null
+++ b/delta.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+import sys
+import os.path
+import difflib
+import tempfile
+import requests
+from hashlib import sha1
+from html2text import html2text
+
+
+def main(url):
+ old_hash = ''
+ changed = True
+
+ html = requests.get(url).text
+ text = html2text(html).encode('utf-8')
+ new_hash = sha1(text).hexdigest()
+
+ urlhash = sha1(url).hexdigest()
+ tmp_path = os.path.join(tempfile.gettempdir(), urlhash)
+
+ if os.path.exists(tmp_path):
+ tmp_file = open(tmp_path, 'r')
+ old_hash = sha1(tmp_file.read()).hexdigest()
+ changed = new_hash != old_hash
+
+ tmp_file = open(tmp_path, 'w')
+ tmp_file.write(text)
+ return changed
+
+
+if __name__ == '__main__':
+ changed = main(sys.argv[1])
+ sys.exit(0 if changed else 1)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..b820185
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+requests
+html2text