aboutsummaryrefslogtreecommitdiffstats
path: root/delta.py
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 /delta.py
downloaddelta-c8d62061cd8cef78e8b0722e40370dae17df109f.tar.gz
delta-c8d62061cd8cef78e8b0722e40370dae17df109f.tar.bz2
delta-c8d62061cd8cef78e8b0722e40370dae17df109f.zip
Initial commitHEADmaster
Diffstat (limited to 'delta.py')
-rwxr-xr-xdelta.py35
1 files changed, 35 insertions, 0 deletions
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)