forked from ArchiveTeam/standalone-readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline.py
137 lines (120 loc) · 5.53 KB
/
pipeline.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import time
import os
import os.path
import shutil
import glob
from seesaw.project import *
from seesaw.config import *
from seesaw.item import *
from seesaw.task import *
from seesaw.pipeline import *
from seesaw.externalprocess import *
from seesaw.tracker import *
DATA_DIR = "data"
USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
VERSION = "20170517.04"
class PrepareDirectories(SimpleTask):
def __init__(self):
SimpleTask.__init__(self, "PrepareDirectories")
def process(self, item):
item_name = item["item_name"]
dirname = "/".join(( DATA_DIR, item_name ))
if os.path.isdir(dirname):
shutil.rmtree(dirname)
os.makedirs(dirname + "/files")
item["item_dir"] = dirname
item["data_dir"] = DATA_DIR
item["warc_file_base"] = "forums.steampowered.com-threads-range-%s-%s" % (item_name, time.strftime("%Y%m%d-%H%M%S"))
class MoveFiles(SimpleTask):
def __init__(self):
SimpleTask.__init__(self, "MoveFiles")
def process(self, item):
os.rename("%(item_dir)s/%(warc_file_base)s.warc.gz" % item,
"%(data_dir)s/%(warc_file_base)s.warc.gz" % item)
shutil.rmtree("%(item_dir)s" % item)
class DeleteFiles(SimpleTask):
def __init__(self):
SimpleTask.__init__(self, "DeleteFiles")
def process(self, item):
os.unlink("%(data_dir)s/%(warc_file_base)s.warc.gz" % item)
def calculate_item_id(item):
thread_htmls = glob.glob("%(item_dir)s/files/forums.steampowered.com/showthread.php*" % item)
n = len(thread_htmls)
if n == 0:
return "null"
else:
return thread_htmls[0] + "-" + thread_htmls[n-1]
project = Project(
title = "Steam Users' Forum",
project_html = """
<img class="project-logo" alt="Steam Logo" src="http://archiveteam.org/images/4/48/Steam_Icon_2014.png" />
<h2>Steam Users' Forum <span class="links"><a href="http://forums.steampowered.com/forums">Website</a> · <a href="http://tracker.archiveteam.org/spuf-grab/">Leaderboard</a></span></h2>
<p>Getting killed June 5th.</p>
""",
utc_deadline = datetime.datetime(2017,06,04, 23,59,0)
)
pipeline = Pipeline(
GetItemFromTracker("http://tracker.archiveteam.org/spuf-grab", downloader, VERSION),
PrepareDirectories(),
WgetDownload([ "./wget-lua",
"-U", USER_AGENT,
"-nv",
"-o", ItemInterpolation("%(item_dir)s/wget.log"),
"--directory-prefix", ItemInterpolation("%(item_dir)s/files"),
"--keep-session-cookies",
"--save-cookies", ItemInterpolation("%(item_dir)s/files/cookies.txt"),
"--force-directories",
"--adjust-extension",
"-e", "robots=off",
"--page-requisites", "--span-hosts",
"--lua-script", "vbulletin.lua",
"--timeout", "10",
"--tries", "3",
"--waitretry", "5"