def main_speech(paths, start, stop, lang): """Create a transcript of each audio file""" paths = Paths(paths, SpeechPath) for path in paths: f = Speech(path, lang) f.scan(start, stop) for time, text in f: echo.out("{:<15}{}", time, text)
def main_dump(name, start_page, stop_page, **kwargs): """This is really here just to test that I can parse a wishlist completely and to demonstrate (by looking at the code) how to iterate through a list""" name = name[0] #pout.v(name, start_page, stop_page, kwargs) #pout.x() pages = set() current_url = "" w = Wishlist() for i, item in enumerate(w.get(name, start_page, stop_page), 1): new_current_url = w.current_url if new_current_url != current_url: current_url = new_current_url echo.h3(current_url) try: item_json = item.jsonable() echo.out("{}. {} is ${:.2f}", i, item_json["title"], item_json["price"]) echo.indent(item_json["url"]) except RobotError: raise except ParseError as e: echo.err("{}. Failed!", i) echo.err(e.body) echo.exception(e) except KeyboardInterrupt: break except Exception as e: echo.err("{}. Failed!", i) echo.exception(e) finally: pages.add(w.current_page) echo.out("Done with wishlist, {} total pages parsed (from {} to {})", len(pages), start_page, stop_page)
def main_dump(paths, directory, dry_run): """dump all or part of the prom data, currently only works on Postgres databases basically just a wrapper around `dump backup` https://github.com/Jaymon/dump """ table_map = get_table_map(paths) for conn_name, conn_info in table_map.items(): inter = conn_info["interface"] conn = inter.connection_config table_names = conn_info["table_names"] cmd = get_base_cmd("backup", inter, directory) cmd.extend(table_names) if dry_run: echo.out(" ".join(cmd)) else: run_cmd(cmd)
def main(name, dry_run): """go through and check wishlist against previous entries""" echo.out( "{}. Starting on wishlist {}", datetime.datetime.utcnow(), name, ) # Let's flush out any problems connecting to the DB before getting into the loop WatchlistItem.interface.connect() name = name[0] email = Email(name) item_count = 1 try: for item_count, we in enumerate(Wishlist(name), item_count): try: echo.out("{}. (p{}) {}", item_count, we.page, we.title) item = Item( uuid=we.uuid, body=we.jsonable(), price=we.price, element=we, ) add_item(email, item, dry_run) except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() email.errors.append((e, (exc_type, exc_value, exc_traceback))) echo.err("{}. Failed!", item_count) echo.exception(e) # bail if we've had a lot of errors or the first N items # have all resulted in an error total_errors = len(email.errors) if total_errors > 25 or (total_errors > 10 and total_errors == item_count): break echo.out( "{}. Done with wishlist, {} total items, {} changes", datetime.datetime.utcnow(), item_count, len(email), ) except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() email.errors.append((e, (exc_type, exc_value, exc_traceback))) echo.exception(e) if not dry_run: email.send(item_count=item_count)
def main_dump(name, **kwargs): """This is really here just to test that I can parse a wishlist completely and to demonstrate (by looking at the code) how to iterate through a list""" name = name[0] #pout.v(name, start_page, stop_page, kwargs) #pout.x() w = Wishlist(name) i = 1 for i, item in enumerate(w, 1): try: item_json = item.jsonable() echo.out("{}. {} is ${:.2f}", i, item_json["title"], item_json["price"]) except RobotError: raise except ParseError as e: echo.err("{}. Failed!", i) echo.err(e.body) echo.exception(e) echo.out("Done with wishlist, {} total items", i)
def callback(res): access_token = client.get_access_token( request_token['oauth_token'], request_token['oauth_token_secret'], res.query.get('oauth_verifier', '') ) echo.hr() echo.out("Your access token is:") echo.out() echo.indent(access_token) echo.out() echo.hr() return access_token
def main_ocr(paths, noflow, words): """run every found image through optical Character Recognition to extract the text the image contains https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html#text-detection """ paths = Paths(paths, ImagePath) for path in paths: f = OCR(path) f.scan() if words: for word in f.words: echo.out(word) elif noflow: echo.out(f.unformatted) else: echo.out(f.text)
def main_auth(**kwargs): """Signin to amazon so you can access private wishlists""" with Wishlist.authenticate() as b: # If you access from another country, amazon might prompt to redirect to # country specific store, we don't want that if b.has_element("#redir-opt-out"): echo.out("Circumventing redirect") remember = b.element("#redir-opt-out") stay = b.element("#redir-stay-at-www") remember.click() stay.click() #button = b.element("a[data-nav-role=signin]") button = b.element("a[id=nav-link-accountList]") echo.out("Clicking sign in button") button.click() # now put in your creds if b.has_element("#continue"): # I'd never seen a flow like this before, it first prompts for email # and then moves onto password email = b.element("#ap_email") submit = b.element("#continue") echo.out("Found alternate signin form") email_in = echo.prompt("Amazon email address") email.send_keys(email_in) submit.click() password = b.element("#ap_password") submit = b.element("#signInSubmit") password_in = echo.prompt("Amazon password") password.send_keys(password_in) echo.out("Signing in") submit.click() else: # typical flow, email/password are on the same page email = b.element("#ap_email") password = b.element("#ap_password") submit = b.element("#signInSubmit") echo.out("Found signin form") email_in = echo.prompt("Amazon email address") password_in = echo.prompt("Amazon password") email.send_keys(email_in) password.send_keys(password_in) echo.out("Signing in") submit.click() # for 2-factor, wait for this element code = b.element("#auth-mfa-otpcode", 5) if code: echo.out( "2-Factor authentication is on, you should be receiving a text" ) submit = b.element("#auth-signin-button") remember = b.element("#auth-mfa-remember-device") remember.click() authcode = echo.prompt("2-Factor authcode") code.send_keys(authcode) submit.click() # original: https://www.amazon.com/ref=gw_sgn_ib/853-0204854-22247543 # 12-1-2017: https://www.amazon.com/?ref_=nav_ya_signin& echo.out("Redirect url was: {}", b.url) if "=gw_sgn_ib" in b.url or "=nav_ya_signin" in b.url: echo.out("Success, you are now signed in") b.cookies.dump()
def main_auth(): """Signin to amazon so you can access private wishlists""" w = Wishlist() with w.open_full() as b: host = w.host echo.out("Requesting {}", host) b.location(host, ignore_cookies=True) # If you access from another country, amazon might prompt to redirect to # country specific store, we don't want that if b.element_exists("#redir-opt-out"): echo.out("Circumventing redirect") remember = b.element("#redir-opt-out") stay = b.element("#redir-stay-at-www") remember.click() stay.click() button = b.element("#a-autoid-0-announce") echo.out("Clicking sign in button") button.click() # now put in your creds email = b.element("#ap_email") password = b.element("#ap_password") submit = b.element("#signInSubmit") if email and password and submit: echo.out("Found sign in form") email_in = echo.prompt("Amazon email address") password_in = echo.prompt("Amazon password") email.send_keys(email_in) password.send_keys(password_in) echo.out("Signing in") submit.click() # for 2-factor, wait for this element code = b.wait_for_element("#auth-mfa-otpcode", 5) if code: echo.out( "2-Factor authentication is on, you should be receiving a text" ) submit = b.element("#auth-signin-button") remember = b.element("#auth-mfa-remember-device") remember.click() authcode = echo.prompt("2-Factor authcode") code.send_keys(authcode) submit.click() #https://www.amazon.com/ref=gw_sgn_ib/853-0204854-22247543 if "/ref=gw_sgn_ib/" in b.current_url: echo.out("Success, you are now signed in") b.save()