changeset 317:9450b557ccac trim

works with one shrunken .cdb, one test case
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 11 Jan 2026 15:07:05 +0000
parents 6c04c30c95d0
children 2502b81838da
files lib/python/cc/lmh/cdb_one.py
diffstat 1 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lib/python/cc/lmh/cdb_one.py	Fri Jan 09 22:31:17 2026 +0000
+++ b/lib/python/cc/lmh/cdb_one.py	Sun Jan 11 15:07:05 2026 +0000
@@ -1,12 +1,18 @@
 #!/usr/bin/python3
-# cython: profile=False
-'''Usage: uz .../cdx-....gz | cdb_one.py cdbpat S E | igzip -c > cdc-...gz
-cdbpat identifies a cdb file
-E.g. .../cdb/ks_%d-%d.cdb
-for segments in S:E
+# cython: profile=False, language_level=3str
+'''Lookup an original cdx entry and add a LastModified time if there is one.
+Usage: uz .../cdx-00nnn.gz | cdb_one.py cdbpat S E DP | igzip -c > cdx-00101.gz
+cdbpat identifies a shrunken cdb file, e.g. .../cdb/ks_%d-%d.cdb
+for segments in S..E.
+The input cdb entries have only a crawl date suffix wrt to a
+ prefix with DP.  For example
+                       a value of 234
+         given a DP of 20230922103943
+ gives a full value of 20230922103234
 '''
 
-import cython, typing, timeit, re, sys
+import cython, typing, timeit, re, sys, array
+
 from db import CCdb
 
 def mainp() -> None:
@@ -24,6 +30,8 @@
 
   S: int = int(sys.argv[2])
   E: int = int(sys.argv[3])
+  DP: cython.bytes = sys.argv[4].encode('ASCII')
+  dpl: int = len(DP)
 
   f = open(sys.argv[1]%(S,E-1),'rb')
   C = CCdb()
@@ -35,10 +43,11 @@
     wdate: cython.bytes
     kind: cython.bytes
     segb: cython.bytes
-    ts: db_memoryviewslice
+    ts: array.array
     seg: int
     res: int
     i: int
+    nd: cython.bytes
     if (m:=C_PAT.match(l)):
       (wdate, uri, segb, kind) = m.groups()
     else:
@@ -46,20 +55,28 @@
     N += 1
     seg = int(segb)
     if (seg >= S and seg < E):
+      # See shrink.py l. 27ff for this shrinkage
+      for i in range(dpl):
+        if wdate[i] != DP[i]:
+          break
+      else:
+        i+=1
+      if i > 0:
+        nd = wdate[i:]
+      else:
+        nd = DP
       if kind == 'robotstxt':
-        wdate += seg
-      if wdate.startswith(b'201908'):
-        wdate = wdate[6:]
+        nd += seg
       if not uri.startswith(b'http'):
         raise ValueError(uri)
-      if (res := C.find(wdate+uri[4:])) == 1:
+      #print(nd,uri[4:],file=sys.stderr)
+      if (res := C.find(nd+uri[4:])) == 1:
         hits += 1
         cdx_out.write(memoryview(l)[:-2])
         cdx_out.write(b', "lastmod": "')
         ts = C.value()
-        if len(ts) > 1 and ts[0] == 48:          # b'0', but not _just_ b'0'
-          cdx_out.write(b'156')
-          cdx_out.write(ts[1:])
+        if len(ts) == 4:
+          cdx_out.write(b'%d'%int.from_bytes(ts))
         else:
           cdx_out.write(ts)
         cdx_out.write(b'"}\n')