Mercurial > hg > cc > cirrus_work
annotate bin/lmh_warc.py @ 56:f8c8f79b2532
rework completely to refill as much as possible only when necessary,
basic loop working again, but not refill
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Mon, 10 Jul 2023 19:52:18 +0100 |
| parents | 11a886a84a49 |
| children | b14187ccfb46 |
| rev | line source |
|---|---|
| 55 | 1 import re,swarc,sys |
|
42
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
2 TUPAT=re.compile(b'^WARC-Target-URI: (.*?)\r',re.MULTILINE) |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
3 LMPAT=re.compile(b'^Last-Modified: (.*?)\r',re.MULTILINE) |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
4 |
| 55 | 5 OUT=open(sys.stdout.fileno(),'wb') |
| 6 | |
|
42
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
7 def showmeLMH(wtype,buf,part): |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
8 global URI |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
9 if part==1: |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
10 if (m:=TUPAT.search(buf)): |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
11 URI=m[1] |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
12 else: |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
13 raise ValueError(b"No target URI in %s ??"%buf) |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
14 else: |
| 55 | 15 mm=LMPAT.findall(buf) |
|
42
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
16 OUT.write(URI) |
| 55 | 17 if mm: |
| 18 for m in mm: | |
| 19 OUT.write(b'\t') | |
| 20 OUT.write(m) | |
|
42
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
21 OUT.write(b'\n') |
|
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
22 |
| 55 | 23 swarc.warc(sys.argv[1],showmeLMH,[b'response'],parts=3) |
|
42
689a0e311cd2
make warc.py a library, separate out testing
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
24 |
