(data, url, content_type, out_file, extra_headers=None)
Constructs a single WARC resource record from an asset (screenshot, uploaded file, etc.)
    and writes to out_file.
Constructs a single WARC resource record from an asset (screenshot, uploaded file, etc.)
    and writes to out_file.
Constructs a single WARC resource record from an asset ( screenshot uploaded file etc . ) and writes to out_file .
def write_resource_record_from_asset(data, url, content_type, out_file, extra_headers=None):
    """
    Constructs a single WARC resource record from an asset (screenshot, uploaded file, etc.)
    and writes to out_file.
    """
    warc_date = warctools.warc.warc_datetime_str(timezone.now()).replace(b'+00:00Z', b'Z')
    headers = [
        (warctools.WarcRecord.TYPE, warctools.WarcRecord.RESOURCE),
        (warctools.WarcRecord.ID, warctools.WarcRecord.random_warc_uuid()),
        (warctools.WarcRecord.DATE, warc_date),
        (warctools.WarcRecord.URL, bytes(url, 'utf-8')),
        (warctools.WarcRecord.BLOCK_DIGEST, bytes(f'sha1:{hashlib.sha1(data).hexdigest()}', 'utf-8'))
    ]
    if extra_headers:
        headers.extend(extra_headers)
    record = warctools.WarcRecord(headers=headers, content=(bytes(content_type, 'utf-8'), data))
    record.write_to(out_file, gzip=True)
def write_resource_record_from_asset ( data , url , content_type , out_file , extra_headers = None ) : warc_date = warctools . warc . warc_datetime_str ( timezone . now ( ) ) . replace ( b'+00:00Z' , b'Z' ) headers = [ ( warctools . WarcRecord . TYPE , warctools . WarcRecord . RESOURCE ) , ( warctools . WarcRecord . ID , warctools . WarcRecord . random_warc_uuid ( ) ) , ( warctools . WarcRecord . DATE , warc_date ) , ( warctools . WarcRecord . URL , bytes ( url , 'utf-8' ) ) , ( warctools . WarcRecord . BLOCK_DIGEST , bytes ( f'sha1:{hashlib.sha1(data).hexdigest()}' , 'utf-8' ) ) ] if extra_headers : headers . extend ( extra_headers ) record = warctools . WarcRecord ( headers = headers , content = ( bytes ( content_type , 'utf-8' ) , data ) ) record . write_to ( out_file , gzip = True )