Skip to content

Instantly share code, notes, and snippets.

@cwells
Created October 26, 2017 03:59
Show Gist options
  • Save cwells/cc39082dc43361ff6b45ebfa8a77b359 to your computer and use it in GitHub Desktop.
Save cwells/cc39082dc43361ff6b45ebfa8a77b359 to your computer and use it in GitHub Desktop.
Gets username from YAML file, password from keyring, otherwise prompt user via click
try:
config = yaml.load(open(CONFIGFILE).read())
except:
config = None
if not config: config = {}
username = config.get('username', None)
password = keyring.get_password(PROGRAM, username) if username else None
@click.command()
@click.option('--username', '-u', type=str, default=username, required=not username)
@click.option('--password', '-p', type=str, hide_input=True, confirmation_prompt=True, default=password, prompt=not password)
def main(username, password):
session = tidalapi.Session()
session.login(username, password)
if not session.check_login():
click.echo("Invalid credentials.")
raise SystemError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment