Prepare V2 corpus, editorial journal and reproducible publication boundary

This commit is contained in:
huncode committed 2026-10-26 17:46:00 +03:00
1 parent 7b3f49788d
commit 69607c52fd
498 files changed
+97671 -468

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
from pathlib import Path
import json,urllib.request,urllib.parse,concurrent.futures,hashlib,time
root=Path(__file__).resolve().parents[1];out=root/'docs/rebuild-v2/raw';out.mkdir(exist_ok=True,parents=True)
old=json.load(open(root/'provenance/cdx-20261026.json'));h=old[0];rows=[dict(zip(h,r)) for r in old[1:]]
wanted=[];seen=set()
for row in rows:
original=row['original'];p=urllib.parse.urlsplit(original);path=urllib.parse.unquote(p.path)
if p.query or row['timestamp']>='20230101':continue
if path in ['/','/page/2/','/контакты/','/полезные-ссылки/','/wp.html'] or __import__('re').match('/20\d\d/\d\d/\d\d/',path):
if path in seen:continue
seen.add(path);wanted.append({'original':original,'timestamp':row['timestamp'],'kind':'article' if __import__('re').match('/20\d\d/\d\d/\d\d/',path) else 'page'})
for path in ['/feed/','/sitemap.xml','/sitemap_index.xml','/wp-sitemap.xml']:
wanted.append({'original':'https://progcode.ru'+path,'timestamp':'20220101000000','kind':'discovery'})
def fetch(rec):
rec=dict(rec);url='https://web.archive.org/web/'+rec['timestamp']+'id_/'+rec['original'];name=hashlib.sha256(url.encode()).hexdigest()[:20]+'.html';rec['requestedSnapshot']=url
try:
with urllib.request.urlopen(url,timeout=50) as res:b=res.read();rec.update(http=res.status,resolvedSnapshot=res.url)
(out/name).write_bytes(b);rec.update(result='downloaded',raw='docs/rebuild-v2/raw/'+name,sha256=hashlib.sha256(b).hexdigest(),bytes=len(b))
except Exception as e:rec.update(result='fetch-failed',error=str(e))
print(rec['result'],rec['original'],rec.get('bytes',rec.get('error')),flush=True)
return rec
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as p:results=list(p.map(fetch,wanted))
(out/'fetch-results.json').write_text(json.dumps(results,ensure_ascii=False,indent=2)+'\n')