archiver/util.py
def parse_url(folder):
    """for a given archive folder, figure out what url it's for"""
    link_json = os.path.join(ARCHIVE_DIR, folder, 'index.json')
    if os.path.exists(link_json):
        with open(link_json, 'r') as f:
            try:
                link_json = f.read().strip()
                if link_json:
                    link = json.loads(link_json)
                    return link['base_url']
            except ValueError:
                print('File contains invalid JSON: {}!'.format(link_json))

    archive_org_txt = os.path.join(ARCHIVE_DIR, folder, 'archive.org.txt')
    if os.path.exists(archive_org_txt):
        with open(archive_org_txt, 'r') as f:
            original_link = f.read().strip().split('/http', 1)[-1]
            with_scheme = 'http{}'.format(original_link)
            return with_scheme

    return ''
for a given archive folder, figure out what url it's for
for a given archive folder, figure out what url it's for
for a given archive folder figure out what url it ' s for
def parse_url(folder):
    link_json = os.path.join(ARCHIVE_DIR, folder, 'index.json')
    if os.path.exists(link_json):
        with open(link_json, 'r') as f:
            try:
                link_json = f.read().strip()
                if link_json:
                    link = json.loads(link_json)
                    return link['base_url']
            except ValueError:
                print('File contains invalid JSON: {}!'.format(link_json))
    archive_org_txt = os.path.join(ARCHIVE_DIR, folder, 'archive.org.txt')
    if os.path.exists(archive_org_txt):
        with open(archive_org_txt, 'r') as f:
            original_link = f.read().strip().split('/http', 1)[-1]
            with_scheme = 'http{}'.format(original_link)
            return with_scheme
    return ''
def parse_url ( folder ) : link_json = os . path . join ( ARCHIVE_DIR , folder , 'index.json' ) if os . path . exists ( link_json ) : with open ( link_json , 'r' ) as f : try : link_json = f . read ( ) . strip ( ) if link_json : link = json . loads ( link_json ) return link [ 'base_url' ] except ValueError : print ( 'File contains invalid JSON: {}!' . format ( link_json ) ) archive_org_txt = os . path . join ( ARCHIVE_DIR , folder , 'archive.org.txt' ) if os . path . exists ( archive_org_txt ) : with open ( archive_org_txt , 'r' ) as f : original_link = f . read ( ) . strip ( ) . split ( '/http' , 1 ) [ - 1 ] with_scheme = 'http{}' . format ( original_link ) return with_scheme return ''
for a given archive folder, figure out what url it's for
for a given archive folder figure out what url it ' s for
"""for a given archive folder, figure out what url it's for"""
folder