How to use wayback - 2 common examples

To help you get started, we’ve selected a few wayback examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kpurdon / waybacklapse / wayback / waybacklapse.py View on Github external
def cli(url, beginning, end, collapse, speed, limit, width, height, verbose, allow_redirects):
    """
    Generate a GIF of a given website over a given time range.
    """

    items = wayback.Wayback(url, limit, beginning, end, collapse).search()
    
    if not os.path.exists(TMP_OUTPUT_DIR):
        os.mkdir(TMP_OUTPUT_DIR)

    # not sure how to correctly set this, trial and error...
    with Pool(processes=12) as pool:
        pool.starmap(capture_url, zip(items, repeat(width), repeat(height),
                                      repeat(allow_redirects)))

    output_fn = create_output_fn(url)

    cmd = 'convert'
    cmd += ' -delay {0}'.format(speed)
    cmd += ' {0}'.format(os.path.join(TMP_OUTPUT_DIR, '*.png'))
    if verbose:
        cmd += ' -verbose'
github kpurdon / waybacklapse / wayback / waybacklapse.py View on Github external
def capture_url(item, width, height, allow_redirects):

    output_fn = os.path.join(TMP_OUTPUT_DIR, '{0}.png'.format(item[0]))
    print('Attemting to capture: {0}'.format(item[1]))

    with closing(webdriver.PhantomJS()) as driver:
        driver.set_window_size(width, height)
        driver.get(item[1])
        try:
            redirect_link = driver.find_element_by_link_text('Impatient?')
            redirected = True  # redirect was found (redirect if allowed)
            if allow_redirects:
                while True:  # continue until all redirects are resolved
                    print('Redirected to: {0}'.format(redirect_link.get_attribute('href')))
                    redirect_link.click()
        except NoSuchElementException:
            redirected = False  # no redirect was found
        except StaleElementReferenceException:
            redirected = True  # redirect resolved before the "impatient" link was clicked
        finally:
            if not redirected or allow_redirects:  # only capture redirect if redirects are allowed
                driver.get_screenshot_as_file(output_fn)

wayback

Python API to Internet Archive Wayback Machine

BSD-3-Clause
Latest version published 6 months ago

Package Health Score

69 / 100
Full package analysis