def checkRow(val, table): for tr in locatrTRs(table): tds = tr.find_elements_by_tag_name("td") if tds[1] == val: click(tds[0]) return True return False
def delete(toDo, task): """Delete a task.""" if toDo is None or toDo.current_task_list is None: click.UsageError('Please load a list first.') else: if all: toDo.current_task_list.delete_all_tasks() click('The list is empty') else: if toDo.current_task_list.tasks.__len__() > 0 and int(task) <= toDo.current_task_list.tasks.__len__(): click.echo('Deleted task: ' + toDo.current_task_list.tasks[int(task)-1].description) toDo.current_task_list.delete(int(task)-1) else: click.BadParameter('There is no task number {} in the list'.format(task))
def getBoundingBox(name, path): filepath = "%s\%s" % (path, name) try: csv_file = open("%s.txt" % (filepath), "rt") except : pass try: csv_file = open("%s.csv" % (filepath), "rt") except : pass try: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: if line_count == 0: click(f'Column names are {", ".join(row)}') line_count += 1 else: click(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.') line_count += 1 print(f'Processed {line_count} lines.') except: click("File not Found!")
def change_map(self, direction): if direction == -1: click(UPPER) time.sleep(TIME_WAIT) self.map_pos[1] -= 1 elif direction == 1: click(LOWER) time.sleep(TIME_WAIT) self.map_pos[1] += 1 elif direction == 2: click(RIGHT) time.sleep(TIME_WAIT) self.map_pos[0] += 1 elif direction == -2: click(LEFT) time.sleep(TIME_WAIT) self.map_pos[0] -= 1
def del_group(organisation, group): """ Delete a group from the given organisation. """ organisation.del_group(group) click("Group {} deleted.".format(group), err=True)
def get_case_summaries(home_url, user, password, query, infile, page_size=100): case_summary_ids = set() case_summaries = [] browser = webdriver.Firefox() browser.implicitly_wait(15) wait = WebDriverWait(browser, 15) browser.get(home_url) username = browser.find_element_by_name("Username") username.send_keys(user) browser.find_element_by_name("Password").send_keys(password) signin = browser.find_element_by_id("SignIn") signin.click() client_id = wait.until( EC.element_to_be_clickable((By.ID, 'co_clientIDTextbox'))) client_id.clear() client_id.send_keys('Q') client_id.send_keys(Keys.ENTER) # caselaw query string if query is not None: # set search field wait.until(EC.element_to_be_clickable( (By.ID, 'searchInputId'))).send_keys(opts['query']) click(By.ID, 'searchButton', wait=wait) click(By.ID, 'co_search_contentNav_link_CASE', wait=wait) # get result counts count_elem = browser.find_element_by_class_name('co_search_titleCount') total = int(count_elem.text[1:-1]) # assumed page size next_page_at = page_size for count in range(1, total + 1): # get each case by ID on this page if count % (next_page_at + 1) == 0: click(by=By.ID, expr='co_search_footer_pagination_next', retries=10, wait=wait) click(by=By.ID, expr="cobalt_result_case_title%d" % (count), wait=wait) try: # test to see if we got a plain single doc result page find(browser=browser, by=By.ID, expr='co_docFixedHeader', retries=1) # test if browser url matches a case if browser.current_url not in case_summary_ids: # summarize this case summary = parse_westlaw_html(browser.page_source) print(summary) case_summaries.append(summary) case_summary_ids.add(browser.current_url) except: print("unable to evaluate %s %d" % (browser.current_url, count)) # return to page with list of case links click(by=By.LINK_TEXT, expr='Return to list', wait=wait) print("%d/%d" % (count, total)) elif infile is not None: # query using an input file with one cases per line count = 0 total = 0 with open(infile) as f: for n in f.readlines(): total += 1 with open(infile) as f: for case in f.readlines(): if case in case_summary_ids: print("skipping %s" % case) else: # use search field case_summary_ids.add(case) wait.until( EC.element_to_be_clickable((By.ID, 'searchInputId'))) searchInput = find(browser=browser, by=By.ID, expr='searchInputId', retries=10) searchInput.clear() searchInput.send_keys(case) click(by=By.ID, expr='searchButton', wait=wait, retries=10) try: find(by=By.ID, expr='co_search_result_heading_content', retries=3) print("warning: ignoring multiple results for %s" % ()) except: try: # did we link to a doc or list find(browser=browser, by=By.ID, expr='co_docFixedHeader', retries=3) print("evaluating: %s" % (browser.title)) summary = parse_westlaw_html(browser.page_source) print(summary) case_summaries.append(summary) browser.back() except WebDriverException as e: print(e) print( "warning: unable to evaluate %s (multiple results?)" % (case)) count += 1 print("%d/%d" % (count, total)) browser.close() return case_summaries
@click.command() @click.option('--img1', required=True, type=str, help='Image that will hide another image') @click.option('--img2', required=True, type=str, help='Image that will be hidden') @click.option('--output', required=True, type=str, help='Output image') def merge(img1, img2, output): merged_image = Steganography.merge(Image.open(img1), Image.open(img2)) merged_image.save(output) @click.command() @click.option('--img', required=True, type=str, help='Image that will be hidden') @click.option('--output', required=True, type=str, help='Output image') def unmerge(img, output): unmerged_image = Steganography.unmerge(Image.open(img)) unmerged_image.save(output) if __name__ == '__main__': click()
def get_briefs(home_url, user, password, infile, informat): # initialize summaries list and selenium vars summaries = [] browser = webdriver.Firefox() browser.implicitly_wait(15) wait = WebDriverWait(browser, 15) # login to westlaw browser.get(home_url) username = browser.find_element_by_name('Username') username.send_keys(user) browser.find_element_by_name('Password').send_keys(password) signin = browser.find_element_by_id('SignIn') signin.click() client_id = wait.until( EC.element_to_be_clickable((By.ID, 'co_clientIDTextbox'))) client_id.send_keys(Keys.ENTER) # open input file and run operations on it with open(infile) as f: for case in f.readlines(): # set query based on informat case_query = {} if informat == 'single': case_query['name'] = case case_query['query'] = case elif informat.lower() == 'fjc': case_input_list = case.split(',') case_query['name'] = case_input_list[1] case_query['query'] = 'PR(' + case_input_list[ 0] + ' Cir.) & DN(' + case_input_list[ 1] + ') & TI(' + case_input_list[ 2] + ' & ' + case_input_list[ 3] + ') & DA(' + case_input_list[4] + ')' else: print('--informat not recognized. setting to single') case_query['name'] = case case_query['query'] = case # make case folder to store brief downloads os.chdir('output') os.mkdir(case_query['name']) os.chdir(case_query['name']) # set search field wait.until(EC.element_to_be_clickable((By.ID, 'searchInputId'))) searchInput = find(browser=browser, by=By.ID, expr='searchInputId', retries=10) searchInput.clear() searchInput.send_keys(case_query['query']) click(by=By.ID, expr='searchButton', wait=wait, retries=10) # wait for case to load or click first result if format is 'FJC' if informat == 'single': try: wait.until( EC.presence_of_element_located((By.ID, 'co_document'))) find(browser=browser, by=By.ID, expr='co_docFixedHeader', retries=3) print('evaluating: %s' % (browser.title)) except: print('No case returned') summary = [case_query['name'], 'No case returned'] summaries.append(summary) os.chdir('../../') continue elif informat.lower() == 'fjc': try: wait.until( EC.presence_of_element_located( (By.ID, 'cobalt_search_case_results'))) find(browser=browser, by=By.ID, expr='cobalt_result_case_title1', retries=3) click(by=By.ID, expr='cobalt_result_case_title1', wait=wait, retries=10) print('evaluating: %s' % (browser.title)) except: print('No case returned') summary = [case_query['name'], 'No case returned'] summaries.append(summary) os.chdir('../../') continue # click filings tab wait.until( EC.text_to_be_present_in_element( (By.ID, 'coid_relatedInfo_riFilings_link'), 'Filings (')) wait.until( EC.element_to_be_clickable( (By.ID, 'coid_relatedInfo_riFilings_link'))) click(by=By.ID, expr='coid_relatedInfo_riFilings_link', wait=wait, retries=10) # get dockets and briefs using a bear of an Xpath expression wait.until( EC.presence_of_element_located( (By.ID, 'co_relatedInfo_table_filings'))) # skip cases with pages of filings if len( browser.find_elements_by_css_selector( '.co_navFooter_pagination')) > 0: os.chdir('../../') continue dockets = browser.find_elements_by_xpath( '//td[@class="co_detailsTable_content"][following-sibling::td[@class="co_detailsTable_court"][text() != "U.S."] and following-sibling::td[@class="co_detailsTable_type"][text() = "Docket"]]/a' ) briefs = browser.find_elements_by_xpath( '//td[@class="co_detailsTable_content"][following-sibling::td[@class="co_detailsTable_court"][text() != "U.S."] and following-sibling::td[@class="co_detailsTable_type"][text() = "Brief"]]/a' ) filings_page_window = browser.current_window_handle # get data from dockets for docket in dockets: docket_url = docket.get_attribute('href') browser.execute_script('window.open()') browser.switch_to_window(browser.window_handles[1]) browser.get(docket_url) try: try: # update docket wait.until( EC.presence_of_element_located( (By.ID, 'co_docketsUpdate'))) old_url = browser.current_url click(by=By.ID, expr='co_docketsUpdate', wait=wait, retries=10) try: WebDriverWait(browser, 30).until( lambda browser: browser.current_url != old_url ) #waits until docket update is complete by looking for change in URL -- the only way i could figure out how to note the update except: print('Exception!') # write docket summary as timeout summary = [] summary.append(str(case_query['name'])) summary.append('Docket timeout') continue except: print('No docket update button found') continue # parse docket html and add to master summaries list summary = [] summary.append(str(case_query['name'])) summary.extend(parse_docket_html(browser.page_source)) summaries.append(summary) # write docket summary. hardcode headers. not great, but meh os.chdir('../../output') headers = [ 'Case', 'Court', 'Docket', 'Case Subtype', 'Nature of Suit', 'Docket Length' ] write(summaries, headers, 'docket summary.csv') os.chdir(case_query['name']) except: print('No docket at URL!') # go back browser.execute_script('window.close()') browser.switch_to_window(filings_page_window) # get html and pdf versions of briefs for brief in briefs: brief_url = brief.get_attribute('href') browser.execute_script('window.open()') browser.switch_to_window(browser.window_handles[1]) browser.get(brief_url) # check if brief page loads and then download briefs try: wait.until( EC.presence_of_element_located((By.ID, 'co_document'))) download_briefs(browser.page_source) except: print('No brief at URL!') # go back browser.execute_script('window.close()') browser.switch_to_window(filings_page_window) os.chdir('../../') browser.close()