view bin/test_warc.py @ 90:c1a70532444c

flip loops
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 31 Aug 2023 14:14:21 +0100
parents b88fdbe8bfa7
children
line wrap: on
line source

import warc,sys

OUT=open(sys.stdout.fileno(),'wb')

if (debug:=(sys.argv[1]=='-d')):
  sys.argv.pop(1)

tt=int(sys.argv.pop(1))

def showme(wtype,buf,part):
  # This should exactly reproduce a complete warc file if called
  #  as per version 1 below
  if debug:
    OUT.write(b"----start %d-----\n"%part)
  OUT.write(buf)
  if buf[-1]!=10:
    OUT.write(b'\r\n')
  if part==7:
    OUT.write(b'\r\n') # to match complete file formatting
  if debug:
    OUT.write(b"----end %d-----\n"%part)
  return OUT

if tt==1:
  warc.warc(sys.argv[1],showme,[b'response','warcinfo','request','metadata'],parts=int(sys.argv[2]),debug=debug)
elif tt==2:
  warc.warc(sys.argv[1],showme,[b'warcinfo'],parts=int(sys.argv[2]),debug=debug)
elif tt==3:
  warc.warc(sys.argv[1],showme,[b'warcinfo'],whole=True,debug=debug)
elif tt==4:
  warc.warc(sys.argv[1],showme,[b'response','warcinfo','request','metadata'],whole=True,debug=debug)
elif tt==5:
  warc.warc(sys.argv[1],showme,[b'response'],parts=int(sys.argv[2]),debug=debug)