Upload 5 files
Browse filestask definitions
replay script
app installation package
- .gitattributes +1 -0
- replay_url.py +408 -0
- wikiHow:万事指南_2.9.6_apkcombo.com.apk +3 -0
- wikihow-canonical.tar.xz +3 -0
- wikihow-extended.tar.xz +3 -0
- wikihow-microcanon.tar.xz +3 -0
.gitattributes
CHANGED
|
@@ -52,3 +52,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 52 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 53 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 52 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 53 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
wikiHow:万事指南_2.9.6_apkcombo.com.apk filter=lfs diff=lfs merge=lfs -text
|
replay_url.py
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 7 |
+
import datetime
|
| 8 |
+
import locale
|
| 9 |
+
import gzip
|
| 10 |
+
import lxml.html
|
| 11 |
+
import lxml.cssselect
|
| 12 |
+
from pyserini.search.lucene import LuceneSearcher
|
| 13 |
+
import csv
|
| 14 |
+
import urllib.parse
|
| 15 |
+
from typing import List
|
| 16 |
+
from typing import Mapping
|
| 17 |
+
from mitmproxy.coretypes.multidict import MultiDict
|
| 18 |
+
import random
|
| 19 |
+
|
| 20 |
+
class Replayer:
|
| 21 |
+
# class `Replayer` {{{ #
|
| 22 |
+
def __init__(self, start_cache_index: int,
|
| 23 |
+
replay_path: str,
|
| 24 |
+
template_path: str,
|
| 25 |
+
index_path: str,
|
| 26 |
+
meta_path: str):
|
| 27 |
+
self.cache_index: int = start_cache_index
|
| 28 |
+
|
| 29 |
+
self.replay_path: str = replay_path
|
| 30 |
+
self.template_path: str = template_path
|
| 31 |
+
self.index_path: str = index_path
|
| 32 |
+
self.meta_path: str = meta_path
|
| 33 |
+
with open(meta_path) as f:
|
| 34 |
+
reader = csv.DictReader(f)
|
| 35 |
+
self.meta_database: Dict[str, Mapping[str, str]]\
|
| 36 |
+
= {itm["doc_id"]: itm for itm in reader}
|
| 37 |
+
self.doc_list: List[str] = list(self.meta_database.keys())
|
| 38 |
+
|
| 39 |
+
locale.setlocale(locale.LC_TIME, "en_US.utf8")
|
| 40 |
+
self.dateformat: str = "%a, %d %b %Y %H:%M:%S GMT"
|
| 41 |
+
self.searcher: LuceneSearcher = LuceneSearcher(self.index_path)
|
| 42 |
+
|
| 43 |
+
# CSS Selectors {{{ #
|
| 44 |
+
self.search_input_selector: lxml.cssselect.CSSSelector\
|
| 45 |
+
= lxml.cssselect.CSSSelector("input#hs_query", translator="html")
|
| 46 |
+
self.result_list_selector: lxml.cssselect.CSSSelector\
|
| 47 |
+
= lxml.cssselect.CSSSelector("div#searchresults_list.wh_block", translator="html")
|
| 48 |
+
self.result_list_anchor_selector: lxml.cssselect.CSSSelector\
|
| 49 |
+
= lxml.cssselect.CSSSelector("div#search_adblock_bottom", translator="html")
|
| 50 |
+
self.result_footer_anchor_selector: lxml.cssselect.CSSSelector\
|
| 51 |
+
= lxml.cssselect.CSSSelector("div#searchresults_footer>div.sr_text", translator="html")
|
| 52 |
+
|
| 53 |
+
self.result_thumb_selector: lxml.cssselect.CSSSelector\
|
| 54 |
+
= lxml.cssselect.CSSSelector("div.result_thumb", translator="html")
|
| 55 |
+
self.result_title_selector: lxml.cssselect.CSSSelector\
|
| 56 |
+
= lxml.cssselect.CSSSelector("div.result_title", translator="html")
|
| 57 |
+
self.result_view_selector: lxml.cssselect.CSSSelector\
|
| 58 |
+
= lxml.cssselect.CSSSelector("li.sr_view", translator="html")
|
| 59 |
+
self.result_updated_selector: lxml.cssselect.CSSSelector\
|
| 60 |
+
= lxml.cssselect.CSSSelector("li.sr_updated", translator="html")
|
| 61 |
+
self.result_verif_selector: lxml.cssselect.CSSSelector\
|
| 62 |
+
= lxml.cssselect.CSSSelector("li.sp_verif", translator="html")
|
| 63 |
+
self.sha_index_selector: lxml.cssselect.CSSSelector\
|
| 64 |
+
= lxml.cssselect.CSSSelector("input[name=\"sha_index\"]", translator="html")
|
| 65 |
+
self.sha_id_selector: lxml.cssselect.CSSSelector\
|
| 66 |
+
= lxml.cssselect.CSSSelector("input[name=\"sha_id\"]", translator="html")
|
| 67 |
+
self.sha_title_selector: lxml.cssselect.CSSSelector\
|
| 68 |
+
= lxml.cssselect.CSSSelector("input[name=\"sha_title\"]", translator="html")
|
| 69 |
+
# }}} CSS Selectors #
|
| 70 |
+
|
| 71 |
+
self.search_page_capacity: int = 30
|
| 72 |
+
self.search_capacity: int = 300
|
| 73 |
+
|
| 74 |
+
def request(self, flow: http.HTTPFlow):
|
| 75 |
+
if flow.request.pretty_host=="www.wikihow.com":
|
| 76 |
+
url_path = flow.request.path
|
| 77 |
+
url_key = classify_url.classify(url_path)
|
| 78 |
+
if url_key in [ r"/x/collect\?t={first,later}&*"
|
| 79 |
+
, r"/x/collect\?t={exit,amp}&*"
|
| 80 |
+
, r"/x/amp-view\?*"
|
| 81 |
+
, r"/ev/*"
|
| 82 |
+
]:
|
| 83 |
+
# Control Flows {{{ #
|
| 84 |
+
headers = {}
|
| 85 |
+
|
| 86 |
+
response_time = datetime.datetime.utcnow()
|
| 87 |
+
headers["retry-after"] = "0"
|
| 88 |
+
headers["accept-ranges"] = "bytes"
|
| 89 |
+
headers["date"] = response_time.strftime(self.dateformat)
|
| 90 |
+
headers["x-timer"] = "S{:.6f},VS0,VE0".format(response_time.timestamp())
|
| 91 |
+
headers["x-c"] = "cache-tyo{:d}-TYO,M".format(self.cache_index)
|
| 92 |
+
headers["x-content-type-options"] = "nosniff"
|
| 93 |
+
headers["x-xss-protection"] = "1; mode=block"
|
| 94 |
+
headers["strict-transport-security"] = "max-age=31536000; includeSubDomains; preload"
|
| 95 |
+
headers["content-type"] = "text/plain; charset=UTF-8"
|
| 96 |
+
headers["x-robots-tag"] = "noindex, nofollow"
|
| 97 |
+
|
| 98 |
+
flow.response = http.Response.make(204,
|
| 99 |
+
headers=headers)
|
| 100 |
+
|
| 101 |
+
self.cache_index += 1
|
| 102 |
+
# }}} Control Flows #
|
| 103 |
+
elif url_path.startswith("/wikiHowTo?search="):
|
| 104 |
+
# Search Pages {{{ #
|
| 105 |
+
url_items = urllib.parse.urlparse(url_path)
|
| 106 |
+
queries = urllib.parse.parse_qs(url_items.query)
|
| 107 |
+
search_keywords = queries["search"][0]
|
| 108 |
+
start_index = int(queries.get("start", ["0"])[0])
|
| 109 |
+
|
| 110 |
+
hits = self.searcher.search(search_keywords, k=self.search_capacity)
|
| 111 |
+
response_time = datetime.datetime.utcnow()
|
| 112 |
+
|
| 113 |
+
# build the webpage
|
| 114 |
+
page_body = lxml.html.parse(
|
| 115 |
+
os.path.join(self.template_path, "search-page.html.template")).getroot()
|
| 116 |
+
|
| 117 |
+
# 1. fill the parameters in the page body
|
| 118 |
+
search_input = self.search_input_selector(page_body)[0]
|
| 119 |
+
search_input.set("value", search_keywords)
|
| 120 |
+
|
| 121 |
+
# 2. prepare result list
|
| 122 |
+
#result_list = self.result_list_selector(page_body)[0]
|
| 123 |
+
result_list_bottom = self.result_list_anchor_selector(page_body)[0]
|
| 124 |
+
with open(os.path.join(self.template_path, "search-item.html.template")) as f:
|
| 125 |
+
result_item_html = "".join(f.readlines())
|
| 126 |
+
for i, h in zip(range(start_index, start_index+self.search_page_capacity),
|
| 127 |
+
hits[start_index:start_index+self.search_page_capacity]):
|
| 128 |
+
docid = h.docid
|
| 129 |
+
article_path = docid.replace("%2f", "/")
|
| 130 |
+
|
| 131 |
+
result_item = lxml.html.fromstring(result_item_html)
|
| 132 |
+
|
| 133 |
+
# Update Item Parameters {{{ #
|
| 134 |
+
result_item.set("href", "https://www.wikihow.com/{:}".format(article_path))
|
| 135 |
+
|
| 136 |
+
result_thumb = self.result_thumb_selector(result_item)[0]
|
| 137 |
+
thumb_url = self.meta_database[docid]["thumb_url"]
|
| 138 |
+
if thumb_url!="":
|
| 139 |
+
result_thumb.set("style",
|
| 140 |
+
"background-image: url(https://www.wikihow.com{:})".format(thumb_url.replace("%2f", "/")))
|
| 141 |
+
else:
|
| 142 |
+
result_thumb.set("style",
|
| 143 |
+
"background-image: url(https://www.wikihow.com/5/5f/{doc_id:}-Step-2.jpg/-crop-250-145-193px-{doc_id}-Step-2.jpg)".format(doc_id=article_path))
|
| 144 |
+
|
| 145 |
+
new_result_title = lxml.html.fromstring(
|
| 146 |
+
"<div class=\"result_title\">{:}</div>"\
|
| 147 |
+
.format(" ".join(
|
| 148 |
+
map( lambda w: "<b>" + w + "</b>"
|
| 149 |
+
, self.meta_database[docid]["title"].split()
|
| 150 |
+
)
|
| 151 |
+
)
|
| 152 |
+
)
|
| 153 |
+
)
|
| 154 |
+
result_title = self.result_title_selector(result_item)[0]
|
| 155 |
+
result_title.getparent().replace(result_title, new_result_title)
|
| 156 |
+
|
| 157 |
+
result_view = self.result_view_selector(result_item)[0]
|
| 158 |
+
view_counts = self.meta_database[docid]["sr_view"]
|
| 159 |
+
if view_counts!="":
|
| 160 |
+
result_view.text = "{:} views\t\t\t\t\t\t".format(view_counts)
|
| 161 |
+
else:
|
| 162 |
+
result_view.text = "0 views\t\t\t\t\t\t"
|
| 163 |
+
|
| 164 |
+
result_updated = self.result_updated_selector(result_item)[0]
|
| 165 |
+
updated_date = self.meta_database[docid]["sr_updated"]
|
| 166 |
+
if updated_date!="":
|
| 167 |
+
updated_date = datetime.datetime.strptime(updated_date,
|
| 168 |
+
"%B %d, %Y")
|
| 169 |
+
updating_duration = response_time - updated_date
|
| 170 |
+
# Calculate Time Diff String {{{ #
|
| 171 |
+
days = updating_duration.days
|
| 172 |
+
if days<7:
|
| 173 |
+
time_diff_str = "{:} day{:} ago".format(
|
| 174 |
+
days, "" if days==1 else "s")
|
| 175 |
+
elif days<30:
|
| 176 |
+
weeks = days // 7
|
| 177 |
+
time_diff_str = "{:} week{:} ago".format(
|
| 178 |
+
weeks, "" if weeks==1 else "s")
|
| 179 |
+
elif days<365:
|
| 180 |
+
months = days // 30
|
| 181 |
+
time_diff_str = "{:} month{:} ago".format(
|
| 182 |
+
months, "" if months==1 else "s")
|
| 183 |
+
else:
|
| 184 |
+
years = days // 365
|
| 185 |
+
time_diff_str = "{:} year{:} ago".format(
|
| 186 |
+
years, "" if years==1 else "s")
|
| 187 |
+
# }}} Calculate Time Diff String #
|
| 188 |
+
list(result_updated)[0].tail = time_diff_str + "\t\t\t\t\t\t"
|
| 189 |
+
else:
|
| 190 |
+
list(result_updated)[0].tail = "12 hours ago\t\t\t\t\t\t"
|
| 191 |
+
|
| 192 |
+
result_verif = self.result_verif_selector(result_item)[-1]
|
| 193 |
+
verif_type = self.meta_database[docid]["sr_verif"]
|
| 194 |
+
if verif_type=="E":
|
| 195 |
+
result_verif.text = "Expert Co-Authored\t\t\t\t\t\t\t"
|
| 196 |
+
elif verif_type=="Q":
|
| 197 |
+
result_verif.text = "Quality Tested\t\t\t\t\t\t\t"
|
| 198 |
+
else:
|
| 199 |
+
result_verif.getparent().remove(result_verif)
|
| 200 |
+
|
| 201 |
+
sha_index = self.sha_index_selector(result_item)[0]
|
| 202 |
+
sha_index.set("value", str(i+1))
|
| 203 |
+
|
| 204 |
+
sha_id = self.sha_id_selector(result_item)[0]
|
| 205 |
+
sha_id.set("value", self.meta_database[docid]["sha_id"])
|
| 206 |
+
|
| 207 |
+
sha_title = self.sha_title_selector(result_item)[0]
|
| 208 |
+
sha_title.set("value", article_path)
|
| 209 |
+
# }}} Update Item Parameters #
|
| 210 |
+
|
| 211 |
+
result_list_bottom.addprevious(result_item)
|
| 212 |
+
|
| 213 |
+
# 3. prepare footer
|
| 214 |
+
result_footer_bottom = self.result_footer_anchor_selector(page_body)[0]
|
| 215 |
+
with open(os.path.join(self.template_path, "search-button.html.template")) as f:
|
| 216 |
+
result_footer = lxml.html.fromstring("".join(f.readlines()))
|
| 217 |
+
next_button, previous_button, statistics_text = list(result_footer)
|
| 218 |
+
|
| 219 |
+
if start_index+self.search_page_capacity<self.search_capacity:
|
| 220 |
+
# has next
|
| 221 |
+
next_button.set("href", "/wikiHowTo?search={:}&start={:}&wh_an=1".format(
|
| 222 |
+
urllib.parse.quote_plus(search_keywords),
|
| 223 |
+
start_index+self.search_page_capacity))
|
| 224 |
+
result_footer_bottom.addprevious(next_button)
|
| 225 |
+
else:
|
| 226 |
+
disabled_next = lxml.html.fromstring(
|
| 227 |
+
"<span class=\"button buttonright primary disabled\">Next ></span>")
|
| 228 |
+
result_footer_bottom.addprevious(disabled_next)
|
| 229 |
+
|
| 230 |
+
if start_index>0:
|
| 231 |
+
# has previous
|
| 232 |
+
enabled_previous = lxml.html.fromstring(
|
| 233 |
+
"<a class=\"button buttonleft primary\">< Previous</a>")
|
| 234 |
+
enabled_previous.set("href",
|
| 235 |
+
"/wikiHowTo?search={:}&start={:}&wh_an=1".format(
|
| 236 |
+
urllib.parse.quote_plus(search_keywords),
|
| 237 |
+
start_index-self.search_page_capacity))
|
| 238 |
+
result_footer_bottom.addprevious(enabled_previous)
|
| 239 |
+
else:
|
| 240 |
+
result_footer_bottom.addprevious(previous_button)
|
| 241 |
+
|
| 242 |
+
statistics_text.text = "{:} Results".format(self.search_capacity)
|
| 243 |
+
result_footer_bottom.addprevious(statistics_text)
|
| 244 |
+
|
| 245 |
+
# 4. return result
|
| 246 |
+
full_page = lxml.html.tostring(page_body)
|
| 247 |
+
|
| 248 |
+
headers = {}
|
| 249 |
+
headers["content-type"] = "text/html; charset=UTF-8"
|
| 250 |
+
headers["content-language"] = "en"
|
| 251 |
+
headers["x-frame-options"] = "SAMEORIGIN"
|
| 252 |
+
headers["x-p"] = "ma"
|
| 253 |
+
headers["expires"] = (response_time + datetime.timedelta(days=1))\
|
| 254 |
+
.strftime(self.dateformat)
|
| 255 |
+
headers["cache-control"] = "s-maxage=86400, must-revalidate, max-age=0"
|
| 256 |
+
headers["content-encoding"] = "gzip"
|
| 257 |
+
headers["accept-ranges"] = "bytes"
|
| 258 |
+
headers["date"] = response_time.strftime(self.dateformat)
|
| 259 |
+
headers["age"] = "0"
|
| 260 |
+
headers["x-timer"] = "S{:.6f},VS0,VE0".format(response_time.timestamp())
|
| 261 |
+
headers["x-c"] = "cache-tyo{:d}-TYO,M".format(self.cache_index)
|
| 262 |
+
headers["x-content-type-options"] = "nosniff"
|
| 263 |
+
headers["x-xss-protection"] = "1; mode=block"
|
| 264 |
+
headers["strict-transport-security"] = "max-age=31536000; includeSubDomains; preload"
|
| 265 |
+
headers["set-cookie"] =\
|
| 266 |
+
"whv=lbYVTnTp1cUHHoDGDOwR; expires={:}; domain=.wikihow.com; path=/; secure"\
|
| 267 |
+
.format((response_time + datetime.timedelta(days=3654)).strftime(self.dateformat))
|
| 268 |
+
headers["vary"] = "Cookie, Accept-Encoding"
|
| 269 |
+
|
| 270 |
+
flow.response = http.Response.make(200,
|
| 271 |
+
content=full_page,
|
| 272 |
+
headers=headers)
|
| 273 |
+
|
| 274 |
+
self.cache_index += 1
|
| 275 |
+
# }}} Search Pages #
|
| 276 |
+
elif url_path.startswith("/Special:Randomizer"):
|
| 277 |
+
# Random Page {{{ #
|
| 278 |
+
random_index = random.randrange(len(self.doc_list))
|
| 279 |
+
doc_id = self.doc_list[random_index]
|
| 280 |
+
article_path = doc_id.replace("%2f", "/")
|
| 281 |
+
|
| 282 |
+
headers = {}
|
| 283 |
+
|
| 284 |
+
response_time = datetime.datetime.utcnow()
|
| 285 |
+
headers["content-type"] = "text/html; charset=UTF-8"
|
| 286 |
+
headers["expires"] = "Thu, 01 Jan 1970 00:00:00 GMT"
|
| 287 |
+
headers["cache-control"] = "private, must-revalidate, max-age=0"
|
| 288 |
+
headers["x-p"] = "ma"
|
| 289 |
+
headers["location"] = "https://www.wikihow.com/{:}".format(article_path)
|
| 290 |
+
headers["content-encoding"] = "gzip"
|
| 291 |
+
headers["accept-ranges"] = "bytes"
|
| 292 |
+
headers["date"] = response_time.strftime(self.dateformat)
|
| 293 |
+
headers["x-timer"] = "S{:.6f},VS0,VE0".format(response_time.timestamp())
|
| 294 |
+
headers["x-c"] = "cache-tyo{:d}-TYO,M".format(self.cache_index)
|
| 295 |
+
headers["x-content-type-options"] = "nosniff"
|
| 296 |
+
headers["x-xss-protection"] = "1; mode=block"
|
| 297 |
+
headers["strict-transport-security"] = "max-age=31536000; includeSubDomains; preload"
|
| 298 |
+
headers["vary"] = "Cookie, Accept-Encoding"
|
| 299 |
+
|
| 300 |
+
flow.response = http.Response.make(302,
|
| 301 |
+
headers=headers)
|
| 302 |
+
|
| 303 |
+
self.cache_index += 1
|
| 304 |
+
# }}} Random Page #
|
| 305 |
+
elif url_path.startswith("/Special:RateItem"):
|
| 306 |
+
# Reting Flows {{{ #
|
| 307 |
+
headers = {}
|
| 308 |
+
|
| 309 |
+
response_time = datetime.datetime.utcnow()
|
| 310 |
+
headers["content-type"] = "text/html; charset=UTF-8"
|
| 311 |
+
headers["access-control-allow-credentials"] = "true"
|
| 312 |
+
headers["access-control-allow-origin"] = "https://www.wikihow.com"
|
| 313 |
+
headers["access-control-expose-headers"] = "AMP-Access-Control-Allow-Source-Origin"
|
| 314 |
+
headers["amp-access-control-allow-source-origin"] = "https://www.wikihow.com"
|
| 315 |
+
#headers["set-cookie"] =\
|
| 316 |
+
#"UseDC=master; expires={:}; Max-Age=10; path=/; domain=www.wikihow.com; secure; HttpOnly"
|
| 317 |
+
headers["content-language"] = "en"
|
| 318 |
+
headers["x-frame-options"] = "SAMEORIGIN"
|
| 319 |
+
headers["expires"] = "Thu, 01 Jan 1970 00:00:00 GMT"
|
| 320 |
+
headers["cache-control"] = "private, must-revalidate, max-age=0"
|
| 321 |
+
headers["x-p"] = "ck ma"
|
| 322 |
+
headers["content-encoding"] = "gzip"
|
| 323 |
+
headers["accept-ranges"] = "bytes"
|
| 324 |
+
headers["date"] = response_time.strftime(self.dateformat)
|
| 325 |
+
headers["x-timer"] = "S{:.6f},VS0,VE0".format(response_time.timestamp())
|
| 326 |
+
headers["x-c"] = "cache-tyo{:d}-TYO,M".format(self.cache_index)
|
| 327 |
+
headers["x-content-type-options"] = "nosniff"
|
| 328 |
+
headers["x-xss-protection"] = "1; mode=block"
|
| 329 |
+
headers["strict-transport-security"] = "max-age=31536000; includeSubDomains; preload"
|
| 330 |
+
headers["vary"] = "Cookie, Accept-Encoding"
|
| 331 |
+
|
| 332 |
+
flow.response = http.Response.make(200,
|
| 333 |
+
content=b'{"result":"true"}',
|
| 334 |
+
headers=headers)
|
| 335 |
+
|
| 336 |
+
cookies_attribute = MultiDict([
|
| 337 |
+
("expires", (response_time + datetime.timedelta(seconds=10))\
|
| 338 |
+
.strftime(self.dateformat)),
|
| 339 |
+
("Max-Age", "10"),
|
| 340 |
+
("path", "/"),
|
| 341 |
+
("domain", "www.wikihow.com"),
|
| 342 |
+
("secure", None),
|
| 343 |
+
("HttpOnly", None)
|
| 344 |
+
])
|
| 345 |
+
flow.response.cookies["UseDC"] = ("master", cookies_attribute)
|
| 346 |
+
flow.response.cookies["UseCDNCache"] = ("false", cookies_attribute.copy())
|
| 347 |
+
|
| 348 |
+
self.cache_index += 1
|
| 349 |
+
# }}} Reting Flows #
|
| 350 |
+
else:
|
| 351 |
+
# Normal Pages {{{ #
|
| 352 |
+
if url_key==r"/Special:RCWidget\?*":
|
| 353 |
+
filename = "%2fSpecial:RCWidget?function=WH.RCWidget.rcwOnLoadData&GuVHo&nabrequest=0&anonview=1"
|
| 354 |
+
else:
|
| 355 |
+
filename = url_path.replace("/", "%2f")
|
| 356 |
+
if len(filename)>100:
|
| 357 |
+
filename = filename[:100]
|
| 358 |
+
|
| 359 |
+
filename = os.path.join(self.replay_path, filename)
|
| 360 |
+
#ctx.log.info("Requesting {:}".format(filename))
|
| 361 |
+
if not os.path.exists(filename):
|
| 362 |
+
ctx.log.info("404: {:}".format(filename))
|
| 363 |
+
flow.response = http.Response.make(404)
|
| 364 |
+
else:
|
| 365 |
+
status_code, header, content = load_response.load_response(filename)
|
| 366 |
+
|
| 367 |
+
if "content-encoding" in header\
|
| 368 |
+
and header["content-encoding"]==b"gzip"\
|
| 369 |
+
and len(content)>0:
|
| 370 |
+
try:
|
| 371 |
+
content = gzip.decompress(content)
|
| 372 |
+
except Exception as e:
|
| 373 |
+
ctx.log.info(str(e))
|
| 374 |
+
|
| 375 |
+
response_time = datetime.datetime.utcnow()
|
| 376 |
+
#if "date" in header:
|
| 377 |
+
#header["date"] = response_time.strftime(self.dateformat)
|
| 378 |
+
#if "last-modified" in header:
|
| 379 |
+
#header["last-modified"] = (response_time - datetime.timedelta(days=1))\
|
| 380 |
+
#.strftime(self.dateformat)
|
| 381 |
+
#if "expires" in header:
|
| 382 |
+
#header["expires"] = (response_time + datetime.timedelta(days=3650))\
|
| 383 |
+
#.strftime(self.dateformat)
|
| 384 |
+
if "x-timer" in header:
|
| 385 |
+
header["x-timer"] = "S{:.6f},VS0,VE0".format(response_time.timestamp())
|
| 386 |
+
if "x-c" in header:
|
| 387 |
+
header["x-c"] = "cache-tyo{:d}-TYO,M".format(self.cache_index)
|
| 388 |
+
|
| 389 |
+
flow.response = http.Response.make(status_code,
|
| 390 |
+
content=content,
|
| 391 |
+
headers=header)
|
| 392 |
+
flow.response.refresh()
|
| 393 |
+
#ctx.log.info("WARN: {:}".format(content==flow.response.content))
|
| 394 |
+
|
| 395 |
+
self.cache_index += 1
|
| 396 |
+
# }}} Normal Pages #
|
| 397 |
+
#else:
|
| 398 |
+
#flow.response = http.Response.make(204)
|
| 399 |
+
#pass
|
| 400 |
+
# }}} class `Replayer` #
|
| 401 |
+
|
| 402 |
+
addons = [ Replayer( 15090 # just a positive integer is ok
|
| 403 |
+
, "dumps" # crawled data from WikiHow website
|
| 404 |
+
, "templates" # templates of the search result page
|
| 405 |
+
, "indices-t/indices" # indices for the search engine based on pyserini
|
| 406 |
+
, "indices-t/docs/doc_meta.csv" # doc meta
|
| 407 |
+
)
|
| 408 |
+
]
|
wikiHow:万事指南_2.9.6_apkcombo.com.apk
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f659af69498271397dd3ae288e40e102d461c9bcabcb99086fc4ca66d8cabff
|
| 3 |
+
size 3586445
|
wikihow-canonical.tar.xz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:08448a322b9f078bb4967a1722f7e50463ed66abf7c5704ed3bd978fc155dcf7
|
| 3 |
+
size 32284
|
wikihow-extended.tar.xz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:511b96180c6dda8fe046a14f9ab9d87f7fe9be724d64d6a693db518460d58577
|
| 3 |
+
size 992928
|
wikihow-microcanon.tar.xz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3be8e6abc081f24d3322f2110a7612565208584cb4631327a60a62257357bb43
|
| 3 |
+
size 14072
|