diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-11-20 12:06:17 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-11-20 12:06:17 +0200 |
commit | c8d62061cd8cef78e8b0722e40370dae17df109f (patch) | |
tree | 1cdd30345f3391254406d3f91b2aafed1f6ff765 /delta.py | |
download | delta-c8d62061cd8cef78e8b0722e40370dae17df109f.tar.gz delta-c8d62061cd8cef78e8b0722e40370dae17df109f.tar.bz2 delta-c8d62061cd8cef78e8b0722e40370dae17df109f.zip |
Diffstat (limited to 'delta.py')
-rwxr-xr-x | delta.py | 35 |
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) |