def main(argv): args = docopt(__doc__, argv=argv) sys.stdout.write('Please enter your Archive.org credentials below to have your\n' 'Archive.org cookies and IA-S3 keys added to your config file.\n\n') username=raw_input('Email address: '), password=getpass('Password: '******'HOME'], '.config') if not os.path.isdir(configdir) and not os.path.isfile(configdir): os.mkdir(configdir) filename = '' if os.path.isdir(configdir): filename = os.path.join(configdir, 'internetarchive.yml') else: filename = os.path.join(os.environ['HOME'], '.internetarchive.yml') if os.path.exists(filename): overwrite = raw_input('\nYou already have an ia config file: ' '{0} \n\nWould you like to overwrite it?' '[y/n] '.format(filename).lower()) if overwrite not in ['y', 'yes']: sys.stdout.write('\nExiting without overwriting config file!\n') sys.exit(1) with open(filename, 'wb') as fp: os.chmod(filename, 0o700) fp.write(configfile) sys.stdout.write('\nSuccessfully saved your new config to: {0}\n'.format(filename))
def configure( # nosec: hardcoded_password_default username: str = "", password: str = "", config_file: str = "", host: str = "", ) -> str: """Configure internetarchive with your Archive.org credentials. :param username: The email address associated with your Archive.org account. :param password: Your Archive.org password. :returns: The config file path. Usage: >>> from internetarchive import configure >>> configure('*****@*****.**', 'password') """ auth_config = config_module.get_auth_config( username or input("Email address: "), password or getpass("Password: "), host, ) config_file_path = config_module.write_config_file(auth_config, config_file) return config_file_path
def login(email, password): """Authenticates user and returns session""" email = email.replace(' ', '+') # We're already logged in, so return a True value if session.get('username'): return session.get('username') try: response = get_auth_config(email, password) # We now know the user's credentials are correct. # Next, we need to get their OpenLibrary username headers = {'Content-Type': 'application/json'} r = requests.post('%s/account/login' % ol_url, headers=headers, json=response.get('s3')) username = r.cookies.get('session').split('/')[2].split('%2C')[0] session['username'] = username session['s3'] = response.get('s3') return username except AuthenticationError: return False
def configure(username=None, password=None, config_file=None, host=None): """Configure internetarchive with your Archive.org credentials. :type username: str :param username: The email address associated with your Archive.org account. :type password: str :param password: Your Archive.org password. Usage: >>> from internetarchive import configure >>> configure('*****@*****.**', 'password') """ username = input('Email address: ') if not username else username password = getpass('Password: ') if not password else password auth_config = config_module.get_auth_config(username, password, host) config_file_path = config_module.write_config_file(auth_config, config_file) return config_file_path