Skip to content

Commit

Permalink
Link to Wayback Diff
Browse files Browse the repository at this point in the history
This commit adds support for linking to the Wayback diff view, rather
than linking to the before and after versions and asking users to be
able to determine the difference (which can be quite small).

Fixes #60
  • Loading branch information
edsu committed Apr 22, 2020
1 parent 458ef4e commit 756569d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions diffengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# maybe this module should be broken up into multiple files, or maybe not ...

UA = "diffengine/0.2.6 (+https://github.com/docnow/diffengine)"
UA = "diffengine/0.2.7 (+https://github.com/docnow/diffengine)"

import os
import re
Expand Down Expand Up @@ -285,6 +285,19 @@ def screenshot_path(self):
def thumbnail_path(self):
return self.screenshot_path.replace('.png', '-thumb.png')

@property
def url(self):

def snap(url):
m = re.match(r'^https://web.archive.org/web/(\d+?)/.*$', url)
return m.group(1) if m else None

return 'https://web.archive.org/web/diff/{}/{}/{}/'.format(
snap(self.old.archive_url),
snap(self.new.archive_url),
self.old.url
)

def generate(self):
if self._generate_diff_html():
self._generate_diff_images()
Expand Down Expand Up @@ -445,7 +458,7 @@ def tweet_diff(diff, token):
if len(status) >= 225:
status = status[0:225] + "…"

status += " " + diff.old.archive_url + " ➜ " + diff.new.archive_url
status += " " + diff.url

try:
twitter.update_with_media(diff.thumbnail_path, status)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.2.6"
version = "0.2.7"

import sys
if sys.version_info < (3,0):
Expand Down
4 changes: 4 additions & 0 deletions test_diffengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def test_diff():
assert os.path.isfile(diff.screenshot_path)
assert os.path.isfile(diff.thumbnail_path)

# check that the url for the internet archive diff is working
assert re.match("^https://web.archive.org/web/diff/\d+/\d+/https.+$",
diff.url)

def test_html_diff():
f = Feed.get(Feed.url=="https://inkdroid.org/feed.xml")
e = f.entries[0]
Expand Down

0 comments on commit 756569d

Please sign in to comment.