Esempio n. 1
0
def language_page_at_index(language, index, testmode=None):
    if testmode is not None:
        lists = get_test_lists(language)
        if testmode == 'all':
            all_list = []
            for l in lists.values():
                all_list.extend(l)
            page = all_list[index]
        else:
            page = lists[testmode][index]
    else:
        page = (Page
                .select()
                .where(Page.language == language)
                .group_by(Page.link)
                .order_by(Page.link)
                .limit(1)
                .offset(index)
                .first())
    return page
def main():

    browser = webdriver.Firefox()

    # Get list of validation pages
    pages = get_test_lists("jquery")["validation"][:NUM_PAGES]

    # For each page, save a screenshot
    for i, p in enumerate(pages):
        print "Visiting page:", p.link, "...",
        browser.get(build_local_url(p))
        screenshot_path = os.path.join(SCREENS_DIR, "page" + str(i) + ".png")
        browser.save_screenshot(screenshot_path)
        print "saved screenshot."
        print "Cropping page...",
        img = Image.open(screenshot_path)
        cropped = img.crop((0, 0, img.width, int(img.width * 1.5)))
        cropped.save(screenshot_path)
        print "cropped."

    browser.close()
Esempio n. 3
0
    count = args.count

    try:
        check_server_running()
    except ServerNotRunningException as e:
        raise SystemExit(e.message)

    ''' Listen for updates to server log to save all detections. '''
    pool = ThreadPoolExecutor(max_workers=1)
    future = pool.submit(save_detections, args.server_file, args.output_file)

    ''' Collect webpages for all micro-languages. '''
    pages = []
    for lang in MICROLANGUAGES:
        test_lists = get_test_lists(lang)
        pages.extend([(p, lang) for p in test_lists[args.testset]])

    ''' Set up progress bar. '''
    widgets = [
        'Progress: ', Percentage(), ' ', Bar(marker=RotatingMarker()), ' ', ETA(),
        ' Visited ', Counter(), ' sites.'
    ]
    num_pages = min(len(pages), count) if count is not None else len(pages)
    pbar = ProgressBar(widgets=widgets, maxval=num_pages)
    pbar.start()

    ''' Set up browser. '''
    browser = webdriver.Firefox()
    load_link(browser, FIRST_LINK)  # start by loading something inconsequential