28 lines
2.1 KiB
Python
28 lines
2.1 KiB
Python
from pathlib import Path
|
|
from urllib.parse import urlsplit
|
|
import sys,json,hashlib,concurrent.futures,time,email.utils
|
|
sys.path.insert(0,str(Path(__file__).parent));from fetch import fetch
|
|
P=Path(__file__).resolve().parents[2];D=P/'docs/rebuild-v2';R=D/'raw'
|
|
plan=json.loads((D/'discovery-plan.json').read_text());inventory=json.loads((D/'url-inventory.json').read_text());known={x['normalizedPath'] for x in plan}
|
|
for e in inventory:
|
|
if e['publicationStatus'].startswith('unresolved') and e['normalizedPath'] not in known and 'mark=topics' not in e['normalizedPath']:
|
|
key=e['normalizedPath'];plan.append(dict(originalUrl=e['originalUrl'],normalizedPath=key,type='linked-content-url',snapshot='2008' if '/forum/' in key or '/shop/' in key else '2012',rawFile='docs/rebuild-v2/raw/pages/'+hashlib.sha256(key.encode()).hexdigest()[:16]+'.html',disposition='fetch',reason=None));known.add(key)
|
|
# Reuse actual successful short-date original, no new text generated from links.
|
|
for item in plan:
|
|
if item['normalizedPath']=='/predpr.shtml':item.update(rawFile='docs/rebuild-v2/raw/predpr-short2012.html',snapshot='2012')
|
|
requests={json.loads(x)['url'] for x in (R/'requests.jsonl').read_text().splitlines()}
|
|
def work(item):
|
|
f=P/item['rawFile']
|
|
if item.get('disposition')!='fetch' or (f.exists() and f.stat().st_size>500):return
|
|
key=item['normalizedPath'];years=['2007','2008'] if '/forum/' in key or '/shop/' in key else ['2012','2008']
|
|
for year in years:
|
|
url='https://web.archive.org/web/'+year+'id_/http://www.videoreg.ru:80'+key
|
|
if url in requests:continue
|
|
name='pages/short-'+hashlib.sha256(url.encode()).hexdigest()[:16]+'.html';rec=fetch(url,name,35)
|
|
if rec['httpStatus']=='200' and rec['bytes']>500:
|
|
item.update(rawFile=rec['raw'],snapshot=year,replayUrl=rec['effectiveUrl']);return
|
|
time.sleep(.35)
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as ex:
|
|
for _ in ex.map(work,plan):(D/'discovery-plan.json').write_text(json.dumps(plan,ensure_ascii=False,indent=2)+'\n')
|
|
print('SHORTDATE BODY COUNT',sum((P/x['rawFile']).exists() and (P/x['rawFile']).stat().st_size>500 for x in plan if x['disposition']=='fetch'))
|