Mercurial > hg > cc > cirrus_work
changeset 325:4c0508e54cca trim
separate date from date+lm itself
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Fri, 23 Jan 2026 15:54:02 +0000 |
| parents | 85612f32e9b6 |
| children | f6643533e971 |
| files | lib/python/cc/lmh/shrink_key.py |
| diffstat | 1 files changed, 11 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/python/cc/lmh/shrink_key.py Fri Jan 23 15:52:59 2026 +0000 +++ b/lib/python/cc/lmh/shrink_key.py Fri Jan 23 15:54:02 2026 +0000 @@ -15,7 +15,14 @@ C_PAT: typing.Pattern[bytes] = re.compile(b'[^ ]* ([^ ]*) .*{"url": "(http[^"]*).*"filename": "[^"]*[.]([0-9][0-9]?)/(warc|robotstxt|crawldiagnostics)/') -def shrink_date(wdate: bytes, dp: bytes, lmb: bytes) -> tuple[bytes,bytes]: +def shrink_key(wdate: bytes, dp: bytes, lmb: bytes) -> tuple[bytes,bytes]: + lm = int(lmb) + if (lm >= 0 and lm <= 2147483647): + lmb=int.to_bytes(lm,4) + #print(nd,uri[4:],file=sys.stderr) + return (shrink_date(wdate,dp),lmb) + +def shrink_date(wdate: bytes, dp: bytes) -> bytes: dpl: int = len(dp) i: int lm: int @@ -25,14 +32,9 @@ else: i+=1 if i > 0: - nd = wdate[i:] + return wdate[i:] else: - nd = dp - lm = int(lmb) - if (lm >= 0 and lm <= 2147483647): - lmb=int.to_bytes(lm,4) - #print(nd,uri[4:],file=sys.stderr) - return (nd,lmb) + return dp if __name__ == "__main__": m: typing.Match[bytes] | None @@ -47,13 +49,12 @@ seg: int res: int nd: bytes - nv: bytes for l in cdx_in: if (m:=C_PAT.match(l)): (wdate, uri, segb, kind) = m.groups() else: raise ValueError(l) - (nd,nv) = shrink_date(wdate,DP,'0') + nd = shrink_date(wdate,DP) seg = int(segb) if kind == 'robotstxt': nd += seg
