forked from palewire/storytracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
74 lines (67 loc) · 2.41 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Generate example materials for the documentation in ./docs/
"""
import os
import storytracker
from PIL import Image
from pprint import pprint
from datetime import datetime
from storytracker import images2gif
urlset = storytracker.ArchivedURLSet([
storytracker.ArchivedURL(
'http://example.com',
datetime(2014, 1, 1, 0, 0, 0),
open("./example/a.html", "rb").read()
),
storytracker.ArchivedURL(
'http://example.com',
datetime(2014, 1, 1, 1, 0, 0),
open("./example/b.html", "rb").read()
),
storytracker.ArchivedURL(
'http://example.com',
datetime(2014, 1, 1, 2, 0, 0),
open("./example/c.html", "rb").read()
),
storytracker.ArchivedURL(
'http://example.com',
datetime(2014, 1, 1, 3, 0, 0),
open("./example/d.html", "rb").read()
),
])
# Run through all the pages
urlset.analyze()
## URL images
obj = storytracker.archive("http://www.cnn.com/")
illo_path = obj.write_illustration_to_directory("./docs/_static/example/")
overlay_path = obj.write_overlay_to_directory("./docs/_static/example/")
os.rename(illo_path, "./docs/_static/example/illo.jpg")
os.rename(overlay_path, "./docs/_static/example/overlay.png")
# URL images
urlset2 = storytracker.ArchivedURLSet([
storytracker.open_wayback_machine_url("https://web.archive.org/web/20140101005148/http://www.bbc.co.uk/news/"),
storytracker.open_wayback_machine_url("https://web.archive.org/web/20140101080323/http://www.bbc.co.uk/news/"),
storytracker.open_wayback_machine_url("https://web.archive.org/web/20140101094432/http://www.bbc.co.uk/news/"),
])
urlset2[0].write_overlay_to_directory("./")
gif_path = urlset2.write_href_overlay_animation_to_directory(
"https://web.archive.org/news/world-africa-25561753",
"./docs/_static/example/"
)
os.rename(gif_path, "./docs/_static/example/href.gif")
urlset[0].write_analysis_report_to_directory("./docs/_static/example/")
urlset.write_analysis_report_to_directory("./docs/_static/example/")
img_list = [
Image.open("./docs/_static/example/href.gif"),
Image.open("./docs/_static/example/overlay.png"),
Image.open("./docs/_static/example/illo.jpg"),
]
crop_list = []
for img in img_list:
crop_list.append(img.crop((0, 0, img.size[0], 400)))
crop_list = storytracker.ArchivedURLSet([]).fit_image_list(crop_list)
images2gif.writeGif(
"./docs/_static/example/href-crop.gif",
crop_list,
duration=1
)