Created
          October 26, 2017 03:59 
        
      - 
      
 - 
        
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
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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