def get_token(): token = keychain.get_password('gistcheck','gistcheck') if token is None: u, p = console.login_alert('GitHub Login') token = auth(u, p)['token'] keychain.set_password('gistcheck','gistcheck',token) return token
def get_token(): token = keychain.get_password('gistcheck', 'gistcheck') if token is None: u, p = console.login_alert('GitHub Login') token = auth(u, p)['token'] keychain.set_password('gistcheck', 'gistcheck', token) return token
def git_push(args): parser = argparse.ArgumentParser(prog='git push' , usage='git push [http(s)://<remote repo> or remote] [-u username[:password]]' , description="Push to a remote repository") parser.add_argument('url', type=str, nargs='?', help='URL to push to') parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]') result = parser.parse_args(args) user, sep, pw = result.u.partition(':') if result.u else (None,None,None) repo = _get_repo() origin='origin' if not result.url: result.url = repo.remotes.get('origin','') if result.url in repo.remotes: origin=result.url result.url=repo.remotes.get(origin) branch_name = os.path.join('refs','heads', repo.active_branch) #'refs/heads/%s' % repo.active_branch print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name) netloc = urlparse.urlparse(result.url).netloc keychainservice = 'stash.git.{0}'.format(netloc) if sep and not user: # -u : clears keychain for this server for service in keychain.get_services(): if service[0]==keychainservice: keychain.delete_password(*service) #Attempt to retrieve user if not user and SAVE_PASSWORDS and result.url.startswith('http'): try: user = dict(keychain.get_services())[keychainservice] except KeyError: user = raw_input('Enter username: '******'Enter password: '******'Enter credentials for {0}'.format(netloc)) if user: if not pw and SAVE_PASSWORDS: pw = keychain.get_password(keychainservice, user) #Check again, did we retrieve a password? if not pw: user, pw = console.login_alert('Enter credentials for {0}'.format(netloc), login=user) #pw = getpass.getpass('Enter password for {0}: '.format(user)) host_with_auth='{}:{}@{}'.format(user,pw,netloc) url=urlparse.urlunparse( urlparse.urlparse(result.url)._replace( netloc=host_with_auth)) porcelain.push(repo.repo.path, url, branch_name) keychain.set_password(keychainservice, user, pw) else: porcelain.push(repo.repo.path, result.url, branch_name) print 'success!'
def _get_key(self): """Retrieve the working copy key or prompt for a new one.""" key = keychain.get_password('wcSync', 'xcallback') if not key: key = console.password_alert('Working Copy Key') keychain.set_password('wcSync', 'xcallback', key) return key
def set_get_user_pass(service): # store username and password in keychain if not found if not service in [x[0] for x in keychain.get_services()]: print 'Keychain does not contain %s username and password.' % service username = raw_input('Enter your %s username and press enter:' % service) password = raw_input('Enter your %s password and press enter:' % service) print 'Username %s and password saved for %s.' % (username, service) keychain.set_password(service, username, password) else: # get the username---can be multiple accounts for one service usernamelist = [x[1] for x in keychain.get_services() if x[0]==service] if len(usernamelist) > 1: print 'Multiple usernames were found for %s.' % service for uname in enumerate(usernamelist): print ' [%d]: %s'%(uname[0]+1, uname[1]) unum = int(raw_input('Enter the number of the correct one:').strip()) - 1 username = usernamelist[unum] else: username = usernamelist[0] # get the password based on correct username password = keychain.get_password(service, username) return username, password
def set_get_user_pass(service): # store username and password in keychain if not found if not service in [x[0] for x in keychain.get_services()]: print 'Keychain does not contain %s username and password.' % service username = raw_input('Enter your %s username and press enter:' % service) password = raw_input('Enter your %s password and press enter:' % service) print 'Username %s and password saved for %s.' % (username, service) keychain.set_password(service, username, password) else: # get the username---can be multiple accounts for one service usernamelist = [ x[1] for x in keychain.get_services() if x[0] == service ] if len(usernamelist) > 1: print 'Multiple usernames were found for %s.' % service for uname in enumerate(usernamelist): print ' [%d]: %s' % (uname[0] + 1, uname[1]) unum = int( raw_input('Enter the number of the correct one:').strip()) - 1 username = usernamelist[unum] else: username = usernamelist[0] # get the password based on correct username password = keychain.get_password(service, username) return username, password
def getGithubPassword(username): service = 'github' password = keychain.get_password(service, username) if password == None: print("Enter password for user", username) password = console.secure_input() keychain.set_password(service, username, password) return password
def getGithubPassword(username): service = 'github' password = keychain.get_password(service, username) if password == None: print "Enter password for user", username password = console.secure_input() keychain.set_password(service, username, password) return password
def _get_key(self): ''' Retrieve the working copy key or prompt for a new one. ''' key = keychain.get_password('wcSync', 'xcallback') if not key: key = console.password_alert('Working Copy Key') keychain.set_password('wcSync', 'xcallback', key) return key
def get_encryption_password(): password = keychain.get_password('EncryptedPDFs', 'password') if password: return password.encode('ascii') password = console.secure_input( 'Enter password to encrypt PDFs: ').rstrip() keychain.set_password('EncryptedPDFs', 'password', password) return password
def save_dropbox_data(username, access_token): """saves dropbox access information for username.""" data = { "api_version": 2, "access_token": access_token, } dumped = pickle.dumps(data) encoded = base64.b64encode(dumped) keychain.set_password(DB_SERVICE, username, encoded)
def _get_key(self): ''' Retrieve the working copy key or prompt for a new one. See https://github.com/ahenry91/wc_sync ''' key = keychain.get_password('wcSync', 'xcallback') if not key: key = console.password_alert('Working Copy Key') keychain.set_password('wcSync', 'xcallback', key) return key
def WC_callback_key(overwrite_key=False): service = "Working Copy" # UUID appended to avoid collision with another script # (generated on original dev machine) account = "x_callback_url_6653ee08-4c43-4453-a400-c5de315b0725" key = keychain.get_password(service, account) if overwrite_key or not key: key = console.input_alert("Enter Working Copy URL key:") keychain.set_password(service, account, key) return key
def get_access_token(): token_str = keychain.get_password('dropbox', app_key) if token_str: key, secret = pickle.loads(token_str) return session.OAuthToken(key, secret) request_token = get_request_token() sess = session.DropboxSession(app_key, app_secret, access_type) access_token = sess.obtain_access_token(request_token) token_str = pickle.dumps((access_token.key, access_token.secret)) keychain.set_password('dropbox', app_key, token_str) return access_token
def test_against_pythonista_keychain(): import keychain set_password('s', 'a', 'password') assert (keychain.get_password('s', 'a') == 'password') keychain.set_password('s', 'a', 'anotherone') assert (get_password('s', 'a') == 'anotherone') keychain.delete_password('s', 'a') assert (get_password('s', 'a') is None)
def push_callback(user,pw): print "Attempting to push to: {0}, branch: {1}".format(remote, branch_name) console.show_activity() if user: opener = auth_urllib2_opener(None, remote, user, pw) porcelain.push(repo.path, remote, branch_name, opener=opener) keychain.set_password(keychainservice, user, pw) else: porcelain.push(repo.repo, result.url, branch_name) console.hide_activity() console.hud_alert('push complete')
def save_options(sender): options = {} options['username'] = options_view['username'].text options['search_base'] = options_view['search_base'].text options['server'] = options_view['server'].text with open(options_path, 'w') as options_file: json.dump(options, options_file) keychain.set_password(keychain_service, options['username'], options_view['password'].text) options_view.close()
def save_dropbox_data(key, sec, access_type, access_token): """saves dropbox access information.""" data = { "app_key": key, "app_sec": sec, "access_type": access_type, "access_token_key": access_token.key, "access_token_sec": access_token.secret } dumped = pickle.dumps(data) encoded = base64.b64encode(dumped) keychain.set_password("stash:mc", "dropbox", encoded)
def git_push(args): parser = argparse.ArgumentParser(prog='git push' , usage='git push [http(s)://<remote repo>] [-u username[:password]]' , description="Push to a remote repository") parser.add_argument('url', type=str, nargs='?', help='URL to push to') parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]') result = parser.parse_args(args) user, sep, pw = result.u.partition(':') if result.u else (None,None,None) repo = _get_repo() #Try to get the remote origin if not result.url: result.url = repo.remotes.get('origin','') branch_name = os.path.join('refs','heads', repo.active_branch) #'refs/heads/%s' % repo.active_branch print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name) netloc = urlparse.urlparse(result.url).netloc keychainservice = 'shellista.git.{0}'.format(netloc) if sep and not user: # -u : clears keychain for this server for service in keychain.get_services(): if service[0]==keychainservice: keychain.delete_password(*service) #Attempt to retrieve user if not user and SAVE_PASSWORDS: try: user = dict(keychain.get_services())[keychainservice] except KeyError: user, pw = console.login_alert('Enter credentials for {0}'.format(netloc)) if user: if not pw and SAVE_PASSWORDS: pw = keychain.get_password(keychainservice, user) #Check again, did we retrieve a password? if not pw: user, pw = console.login_alert('Enter credentials for {0}'.format(netloc), login=user) #pw = getpass.getpass('Enter password for {0}: '.format(user)) opener = auth_urllib2_opener(None, result.url, user, pw) porcelain.push(repo.repo, result.url, branch_name, opener=opener) keychain.set_password(keychainservice, user, pw) else: porcelain.push(repo.repo, result.url, branch_name)
def get_access_token(): token_str = keychain.get_password('dropbox', app_key) if token_str: key, secret = token_str.split(',') return session.OAuthToken(key, secret) request_token = get_request_token() sess = session.DropboxSession(app_key, app_secret, access_type) access_token = sess.obtain_access_token(request_token) key = access_token.key.decode('ascii') secret = access_token.secret.decode('ascii') token_str = key + ',' + secret keychain.set_password('dropbox', app_key, token_str) return session.OAuthToken(key, secret)
def get_credentials(svc): f = filter(lambda x: x[0] == svc, keychain.get_services()) res = [x for x in f] if not res: usr, pwd = console.login_alert(svc) keychain.set_password(svc, usr, pwd) return usr, pwd return (res[0][1], keychain.get_password(*res[0]))
def save_handler(sender): addr_file = open(os.path.join(cur_dir, 'ftp_addr.txt'), 'w') name_file = open(os.path.join(cur_dir, 'ftp_name.txt'), 'w') dir_file = open(os.path.join(cur_dir, 'ftp_dir.txt'), 'w') root_dir_file = open(os.path.join(cur_dir, 'ftp_rootdir.txt'), 'w') addr_file.write(root['addr'].text) name_file.write(root['name'].text) dir_file.write(root['dir'].text) root_dir_file.write(os.path.abspath(root['rootdir'].text)) addr_file.close() name_file.close() dir_file.close() root_dir_file.close() keychain.set_password('ftpsync', root['name'].text, root['pswd'].text)
def commit(): gist = get_gist_id(editor.get_path()) if gist is not None: token = keychain.get_password('gistcheck','gistcheck') if token is None: u, p = console.login_alert('GitHub Login') r = json.loads(auth(u, p)) print r token = r['token'] keychain.set_password('gistcheck','gistcheck',token) fname = os.path.basename(editor.get_path()) m = console.input_alert('Edit Description','Enter a new description:','') if m == '': m = None return edit(gist,{fname:editor.get_text()},token,m)
def __init__(self): config = keychain.get_password('Movie Diary', 'Config') if config == None: moviedb_api = keychain.get_password('MovieDB', 'API') airtable_api = keychain.get_password('Airtable', 'API') airtable_db = keychain.get_password('Airtable', 'Movie Diary') airtable_table = keychain.get_password('Airtable', 'Movie Diary Table') if airtable_api == None or airtable_db == None or airtable_table == None: airtable_api, airtable_db, airtable_table = self.getairtable(airtable_api, airtable_db, airtable_table) config = dialogs.form_dialog(title='Movie Diary Configuration', sections=[('MovieDB', [{'type': 'text', 'key': 'moviedb_api', 'value': moviedb_api if moviedb_api is not None else '84cef43ccf02b1ba6093c9694ed671c9', 'title': 'MovieDB API Token'}]), ('Airtable', [{'type': 'text', 'key': 'airtable_api', 'value': airtable_api, 'title': 'Airtable API Key'}, {'type': 'text', 'key': 'airtable_db', 'value': airtable_db, 'title': 'Airtable database ID'}, {'type': 'text', 'key': 'airtable_table', 'value': airtable_table if airtable_table is not None else 'Table 1', 'title': 'Airtable table name'}]), ('Custom', [{'type': 'switch', 'key': 'set_date_manually', 'value': False, 'title': 'Set date manually'}, {'type': 'switch', 'key': 'add_time_to_date', 'value': False, 'title': 'Add time to date'}]),('Extra Fields', [{'type': 'switch', 'key': 'directors_field', 'value': True, 'title': 'Directors'}, {'type': 'switch', 'key': 'genres_field', 'value': False, 'title': 'Genres'}, {'type': 'switch', 'key': 'runtime_field', 'value': False, 'title': 'Runtime'}, {'type': 'switch', 'key': 'cast_field', 'value': False, 'title': 'Cast'}, {'type': 'switch', 'key': 'imdb_field', 'value': False, 'title': 'IMDB URL'}]),('Fields', [{'type':'text', 'key': 'title_field_name', 'value': 'Title', 'title': 'Title'}, {'type':'text', 'key': 'overview_field_name', 'value': 'Overview', 'title': 'Overview'}, {'type':'text', 'key': 'rating_field_name', 'value': 'Rating', 'title': 'Rating'}, {'type':'text', 'key': 'date_field_name', 'value': 'Date', 'title': 'Date'}, {'type':'text', 'key': 'directors_field_name', 'value': 'Directors', 'title': 'Directors'}, {'type':'text', 'key': 'poster_field_name', 'value': 'Poster', 'title': 'Poster'}, {'type':'text', 'key': 'year_field_name', 'value': 'Year', 'title': 'Year'}, {'type':'text', 'key': 'genres_field_name', 'value': 'Genres', 'title': 'Genres'}, {'type':'text', 'key': 'cast_field_name', 'value': 'Cast', 'title': 'Cast'}, {'type':'text', 'key': 'runtime_field_name', 'value': 'Runtime', 'title': 'Runtime'}, {'type':'text', 'key': 'imdb_field_name', 'value': 'IMDB', 'title': 'IMDB URL'}])]) if config == None: raise MissingConfigError('You must setup and confirm the Movie Diary configuration before continuing.') else: config['moviedb_api'] = self.validate_config(config['moviedb_api'], 'Insert your TMDB API key', 'You need a valid MovieDB API key', '84cef43ccf02b1ba6093c9694ed671c9') config['airtable_api'] = self.validate_config(config['airtable_api'], 'Insert your Airtable API key', 'You need a valid Airtable API key') config['airtable_db'] = self.validate_config(config['airtable_db'], 'Insert your Airtable database ID', 'You need the ID of your database') config['airtable_table'] = self.validate_config(config['airtable_table'], 'Insert the name of yout Airtable table', 'You must insert the name of the table in your database.', 'Table 1', True) keychain.set_password('Movie Diary', 'Config', cPickle.dumps(config)) else: config = cPickle.loads(config) self.moviedb_api = config.get('moviedb_api', '') self.airtable_api = config.get('airtable_api', '') self.airtable_db = config.get('airtable_db', '') self.airtable_table = config.get('airtable_table', '') self.set_date_manually = config.get('set_date_manually', '') self.add_time_to_date = config.get('add_time_to_date', '') self.directors_field = config.get('directors_field', '') self.genres_field = config.get('genres_field', '') self.runtime_field = config.get('runtime_field', '') self.cast_field = config.get('cast_field', '') self.imdb_field = config.get('imdb_field', '') self.title_field_name = config.get('title_field_name', 'Title') self.overview_field_name = config.get('overview_field_name', 'Overview') self.rating_field_name = config.get('rating_field_name', 'Rating') self.date_field_name = config.get('date_field_name', 'Date') self.directors_field_name = config.get('directors_field_name', 'Directors') self.poster_field_name = config.get('poster_field_name', 'Poster') self.year_field_name = config.get('year_field_name', 'Year') self.genres_field_name = config.get('genres_field_name', 'Genres') self.cast_field_name = config.get('cast_field_name', 'Cast') self.runtime_field_name = config.get('runtime_field_name', 'Runtime') self.imdb_field_name = config.get('imdb_field_name', 'IMDB')
def get_access_token(): access_token = keychain.get_password('dropboxv2', app_key) if access_token: return access_token auth_flow = dropbox.DropboxOAuth2FlowNoRedirect(app_key, app_secret) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") webbrowser.open(authorize_url, modal=True) auth_code = input("Enter the authorization code here: ").strip() try: access_token, user_id = auth_flow.finish(auth_code) except Exception as e: print('Error: %s' % (e, )) return keychain.set_password('dropboxv2', app_key, access_token) return access_token
def connect(self): self.api = onedrive.OneDriveAPI(client_id=self.app_key, client_secret=self.app_secret) token_str = keychain.get_password('onedrive', self.app_key) if token_str: at, ac, ar = pickle.loads(token_str) self.api.auth_access_token = at self.api.auth_refresh_token = ar self.auth_code = ac self.api.auth_get_token() else: request_token = self._get_request_token() self.api.auth_user_process_url(request_token) self.api.auth_get_token() keychain.set_password( 'onedrive', self.app_key, pickle.dumps((self.api.auth_access_token, self.api.auth_code, self.api.auth_refresh_token)))
def get_api_key(): api_key = keychain.get_password('moviedb', 'api') If api_key == None: api_key = console.input_alert('No API Key', 'You must generate an api key at https://www.themoviedb.org and enter it here:', '', 'Ok', hide_cancel_button = False) If api_key <> '': api_key = keychain.set_password('moviedb', 'api', api_key) api_key = keychain.get_password('moviedb', 'api')
def get_api_key(): api_key = keychain.get_password('wunderground', 'api') If api_key == None: api_key = console.input_alert('No API Key', 'You must register for a free api key at https://www.wunderground.com/weather/api and enter it here:', '', 'Ok', hide_cancel_button = False) If api_key <> '': api_key = keychain.set_password('wunderground', 'api', api_key) api_key = keychain.get_password('wunderground', 'api')
def connect(self): self.api = onedrive.OneDriveAPI( client_id=self.app_key, client_secret=self.app_secret) token_str = keychain.get_password('onedrive', self.app_key) if token_str: at, ac, ar = pickle.loads(token_str) self.api.auth_access_token = at self.api.auth_refresh_token = ar self.auth_code = ac self.api.auth_get_token() else: request_token = self._get_request_token() self.api.auth_user_process_url(request_token) self.api.auth_get_token() keychain.set_password('onedrive', self.app_key, pickle.dumps(( self.api.auth_access_token, self.api.auth_code, self.api.auth_refresh_token )))
def get_password_from_keychain(service, account, message=None): ''' Retrieve the working copy key or prompt for a new one. See https://github.com/ahenry91/wc_sync ''' if not message: message = "Enter password for account '%s' of service '%s'" % (account, service) key = keychain.get_password(service, account) if not key: try: key = console.password_alert(message) except KeyboardInterrupt as k: key = None if key: keychain.set_password(service, account, key) else: keychain.delete_password(service, account) return key
def push_callback(user, pw): print "Attempting to push to: {0}, branch: {1}".format(remote, branch_name) console.show_activity() if user: try: parsedurl = urlparse.urlparse(remote) host_with_auth = '{}:{}@{}'.format( user, pw, parsedurl.netloc) url = urlparse.urlunparse( parsedurl._replace(netloc=host_with_auth)) porcelain.push(repo.path, url, branch_name) keychain.set_password(keychainservice, user, pw) except urllib2.URLError: console.hide_activity() console.hud_alert('push failed', 'error') return else: porcelain.push(repo.repo, result.url, branch_name) console.hide_activity() console.hud_alert('push complete')
def btn_secret_push(self, sender): tmpsecret = self.secret if tmpsecret is None: tmpsecret = '' tmpsecret = dialogs.text_dialog( title='Set secret', text=tmpsecret, autocorrection=False, autocapitalization=ui.AUTOCAPITALIZE_NONE, spellchecking=False) if tmpsecret is None: return tmpsecret = tmpsecret.strip() if tmpsecret: keychain.set_password(appname, appname, tmpsecret) self.secret = tmpsecret self.activate_button() else: keychain.delete_password(appname, appname) self.secret = None self.deactivate_button()
def get_login(): # Get login data from the keychain, if it has been saved already: login_data_json = keychain.get_password('iTunesConnect', 'Default') if login_data_json is None: # Show input dialogs for vendor id and user/password: vendor_id = console.input_alert('Vendor ID (8xxxxxxx)') user, password = console.login_alert('iTunes Connect Login') if user and password and vendor_id: # Save login data to keychain as json string: login_data = { 'user': user, 'password': password, 'vendor_id': vendor_id } keychain.set_password('iTunesConnect', 'Default', json.dumps(login_data)) else: login_data = json.loads(login_data_json) user = login_data['user'] password = login_data['password'] vendor_id = login_data['vendor_id'] return user, password, vendor_id
def edit_config(self): config = dialogs.form_dialog(title='Movie Diary Configuration', sections=[('MovieDB', [{'type': 'text', 'key': 'moviedb_api', 'value': self.moviedb_api, 'title': 'MovieDB API Token'}]), ('Airtable', [{'type': 'text', 'key': 'airtable_api', 'value': self.airtable_api, 'title': 'Airtable API Key'}, {'type': 'text', 'key': 'airtable_db', 'value': self.airtable_db, 'title': 'Airtable database ID'}, {'type': 'text', 'key': 'airtable_table', 'value': self.airtable_table, 'title': 'Airtable table name'}]), ('Custom', [{'type': 'switch', 'key': 'set_date_manually', 'value': self.set_date_manually, 'title': 'Set date manually'}, {'type': 'switch', 'key': 'add_time_to_date', 'value': self.add_time_to_date, 'title': 'Add time to date'}]),('Extra Fields', [{'type': 'switch', 'key': 'directors_field', 'value': self.directors_field, 'title': 'Directors'}, {'type': 'switch', 'key': 'genres_field', 'value': self.genres_field, 'title': 'Genres'}, {'type': 'switch', 'key': 'runtime_field', 'value': self.runtime_field, 'title': 'Runtime'}, {'type': 'switch', 'key': 'cast_field', 'value': self.cast_field, 'title': 'Cast'}, {'type': 'switch', 'key': 'imdb_field', 'value': self.imdb_field, 'title': 'IMDB URL'}]),('Fields', [{'type':'text', 'key': 'title_field_name', 'value': self.title_field_name, 'title': 'Title'}, {'type':'text', 'key': 'overview_field_name', 'value': self.overview_field_name, 'title': 'Overview'}, {'type':'text', 'key': 'rating_field_name', 'value': self.rating_field_name, 'title': 'Rating'}, {'type':'text', 'key': 'date_field_name', 'value': self.date_field_name, 'title': 'Date'}, {'type':'text', 'key': 'directors_field_name', 'value': self.directors_field_name, 'title': 'Directors'}, {'type':'text', 'key': 'poster_field_name', 'value': self.poster_field_name, 'title': 'Poster'}, {'type':'text', 'key': 'year_field_name', 'value': self.year_field_name, 'title': 'Year'}, {'type':'text', 'key': 'genres_field_name', 'value': self.genres_field_name, 'title': 'Genres'}, {'type':'text', 'key': 'cast_field_name', 'value': self.cast_field_name, 'title': 'Cast'}, {'type':'text', 'key': 'runtime_field_name', 'value': self.runtime_field_name, 'title': 'Runtime'}, {'type':'text', 'key': 'imdb_field_name', 'value': self.imdb_field_name, 'title': 'IMDB URL'}]), ('Serious Stuff', [{'type': 'switch', 'key': 'reset_config', 'title': 'Reset Configuration', 'value': False}])]) if config != None: if config['reset_config']: reset_confirm = console.alert('Reset Configuration?', 'Are you sure? This will only clean your credentials data and has no relation to your database.', 'Cancel', 'Reset', hide_cancel_button=True) if reset_confirm == 2: keychain.delete_password('Movie Diary', 'Config') keychain.delete_password('Airtable', 'API') keychain.delete_password('Airtable', 'Movie Diary') keychain.delete_password('Airtable', 'Movie Diary Table') return console.hud_alert('Movie Diary Configuration Successfully Reset') config['moviedb_api'] = self.validate_config(config['moviedb_api'], 'Insert your TMDB API key', 'You need a valid MovieDB API key', '84cef43ccf02b1ba6093c9694ed671c9') config['airtable_api'] = self.validate_config(config['airtable_api'], 'Insert your Airtable API key', 'You need a valid Airtable API key') config['airtable_db'] = self.validate_config(config['airtable_db'], 'Insert your Airtable database ID', 'You need the ID of your database') config['airtable_table'] = self.validate_config(config['airtable_table'], 'Insert the name of yout Airtable table', 'You must insert the name of the table in your database.', 'Table 1', True) keychain.set_password('Movie Diary', 'Config', cPickle.dumps(config)) console.hud_alert('Movie Diary Configuration Successfully Edited') else: raise MissingConfigError('You must setup and confirm the Movie Diary configuration before continuing.')
def get_weather(lat, lon, bold): err = '' ''' You will need an API key to get weather data. Register for your free key at http:// www.wunderground.com/weather/api ''' api_key = keychain.get_password('wunderground', 'api') If api_key == None: api_key = console.input_alert('No API Key', 'You must register for a free api key at https://www.wunderground.com/weather/api and enter it here:', '', 'Ok', hide_cancel_button = False) If api_key <> '': api_key = keychain.set_password('wunderground', 'api', api_key) api_key = keychain.get_password('wunderground', 'api')
import requests import json import base64 SITE_BRANCH = 'master' # either master or gh-pages COMMITTER = {'name': 'Joe Bloggs', 'email': '*****@*****.**'} #keychain.delete_password('GitHub', 'username') # Uncomment these lines #keychain.delete_password('GitHub', 'token') # to change the details #keychain.delete_password('GitHub', 'repository') # stored in the keychain # Get Username, API Token and Repository username = keychain.get_password('GitHub', 'username') if not username: username = console.input_alert("Username", "Enter your GitHub Username", '', "Save") keychain.set_password('GitHub', 'username', username) tokn = keychain.get_password('GitHub', 'token') if not tokn: tokn = console.password_alert("API Token", "Enter your GitHub API Token", '', "Save") keychain.set_password('GitHub', 'token', tokn) repo = keychain.get_password('GitHub', 'repository') if not repo: repo = console.input_alert("Repository", "Enter your GitHub Repository name", '', "Save") keychain.set_password('GitHub', 'repository', repo) # Mangle the post ;) post_text = editor.get_text() post_sections = post_text.split('---')
moviediary_edit['moviedb_api'] = moviedb_api if moviediary_edit['airtable_api'] == '': airtable_api = console.input_alert('Insert your Airtable API key') if airtable_api == None: raise MissingConfigError('You need a valid Airtable API key') else: moviediary_edit['airtable_api'] = airtable_api if moviediary_edit['airtable_db'] == '': airtable_db = console.input_alert('Insert your Airtable database ID') if airtable_db == None: raise MissingConfigError('You need the ID of your database') else: moviediary_edit['airtable_db'] = airtable_db if moviediary_edit['airtable_table'] == '': airtable_table = console.input_alert('Insert the name of yout Airtable table', '', 'Table 1') if airtable_table == None: raise MissingConfigError('You must insert the name of the table in your database.') else: moviediary_edit['airtable_table'] = quote(airtable_table) keychain.set_password('Movie Diary', 'Config', pickle.dumps(moviediary_edit)) console.hud_alert('Movie Diary Configuration Successfully Edited') except NoConfigError as e: console.alert('No Config', e) except MissingConfigError as e: console.alert('Missing Config Field', e)
def git_push(args): parser = argparse.ArgumentParser( prog='git push', usage= 'git push [http(s)://<remote repo> or remote] [-u username[:password]]', description="Push to a remote repository") parser.add_argument('url', type=str, nargs='?', help='URL to push to') parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]') result = parser.parse_args(args) user, sep, pw = result.u.partition(':') if result.u else (None, None, None) repo = _get_repo() origin = 'origin' if not result.url: result.url = repo.remotes.get('origin', '') if result.url in repo.remotes: origin = result.url result.url = repo.remotes.get(origin) branch_name = os.path.join( 'refs', 'heads', repo.active_branch) #'refs/heads/%s' % repo.active_branch print("Attempting to push to: {0}, branch: {1}".format( result.url, branch_name)) netloc = urlparse.urlparse(result.url).netloc keychainservice = 'stash.git.{0}'.format(netloc) if sep and not user: # -u : clears keychain for this server for service in keychain.get_services(): if service[0] == keychainservice: keychain.delete_password(*service) #Attempt to retrieve user if not user and SAVE_PASSWORDS and result.url.startswith('http'): try: user = dict(keychain.get_services())[keychainservice] except KeyError: user = input('Enter username: '******'Enter password: '******'Enter credentials for {0}'.format(netloc)) outstream = StringIO() if user: if not pw and SAVE_PASSWORDS: pw = keychain.get_password(keychainservice, user) #Check again, did we retrieve a password? if not pw: user, pw = console.login_alert( 'Enter credentials for {0}'.format(netloc), login=user) host_with_auth = '{}:{}@{}'.format(user, pw, netloc) url = urlparse.urlunparse( urlparse.urlparse(result.url)._replace(netloc=host_with_auth)) porcelain.push(repo.repo.path, url, branch_name, errstream=outstream) keychain.set_password(keychainservice, user, pw) else: porcelain.push(repo.repo.path, result.url, branch_name, errstream=outstream) for line in outstream.getvalue().split('\n'): print((line.replace(pw, '*******') if pw else line)) print('success!')
def save_settings(self): settings_str = str(self.settings) # convert dict -> str settings_str = keychain.set_password('Braille','settings',settings_str)
email, password = console.login_alert('LastPass login', '', email, password) device = keychain.get_password('lastpass_uuid', 'lastpass') try: blob = lastpass.Vault.fetch_blob(email, password, None, device) except lastpass.LastPassIncorrectGoogleAuthenticatorCodeError as e: googleauth = None if not device: console.hud_alert(message='You will now be redirected to Google Authenticator',duration=1) webbrowser.open('otpauth:') console.hud_alert(message='Enter the 2FA code',duration=5.0) googleauth = console.input_alert('GoogleAuth', '', clipboard.get()) trusted = console.alert('Trusted', 'Save this device as trusted?', 'Save', 'Don\'t Save', hide_cancel_button=True) if not trusted: device = str(uuid.uuid1()) keychain.set_password('lastpass_uuid', 'lastpass', device) blob = lastpass.Vault.fetch_blob(email, password, googleauth, device) save_vault = console.alert("Save to keychain", "Would you like to save your vault to the keychain?", "Don't Save", "Save", hide_cancel_button=True) if not save_vault: save_blob = console.alert("Save blob local", "Would you like to save the encrypted blob locally?", "Don't Save", "Save", hide_cancel_button=True) if save_blob: import pickle, os print "Saving blob to .lastpass.blob" FILENAME = os.path.join(os.getcwd(),'.lastpass.blob') pickle.dump(blob, open(FILENAME,'wb')) console.hud_alert('Saved blob') else: try: # don't want both the blob and the keychain - avoids conflicts import os
import pickle import cgi import sys # Uncomment this line to reset stored password # keychain.delete_password('vaughanje', 'editorial') login = keychain.get_password('vaughanje', 'editorial') if login is not None: user, pw = pickle.loads(login) else: user, pw = console.login_alert('FTPS Login Needed', 'No login credentials found.') pickle_token = pickle.dumps((user, pw)) keychain.set_password('vaughanje', 'editorial', pickle_token) # remotePath = "/public_html/blog/source/" host = "crawlab.org" port = 21 docTitle = console.input_alert("Filename", "Enter File Name") fileName = docTitle+'.md' confirmation = console.alert('Confirm', 'Go ahead and post?','Yes','No') postContent = sys.argv[1]#editor.get_text()
def __setitem__(self, key, value): keychain.set_password(DB_NAME, key, value)
def checkKey(): global key key = keychain.get_password('wcSync','xcallback') if key == None: pwd = console.password_alert('Working Copy Key') keychain.set_password('wcSync','xcallback',pwd)
import console, keychain device = raw_input('Enter device hostname or IP: ') username = raw_input('Enter username: '******'Enter password: '******'Account saved to keychain.'
def main(): if not appex.is_running_extension(): print('running in pythonista--using test data\n') text = '''## Test Data Generic test data!''' else: text = appex.get_text() if text: author = cfg.post['post_author'] gitlab_url = cfg.post['gitlab_url'] gitlab_user = cfg.post['gitlab_user'] gitlab_repo = cfg.post['gitlab_repo'] gitlab_token = keychain.get_password('gitlab_token', gitlab_user) or '' dbx_token = keychain.get_password('dbx_token', gitlab_user) or '' (title, text) = extract_title(text) filename = '%s-%s.md' % (date.today(), slug(title)) dbx_fields = ( 'Dropbox Settings', [ dict(title='Dropbox Token', key='dbx_token', type='text', value=dbx_token, autocorrection=False, autocapitalization=False) ] ) gitlab_fields = ( 'Gitlab Settings', [ dict(title='Gitlab URL', key='gitlab_url', type='text', value=gitlab_url, autocorrection=False, autocapitalization=False), dict(title='Gitlab User', key='gitlab_user', type='text', value=gitlab_user, autocorrection=False, autocapitalization=False), dict(title='Gitlab Token', key='gitlab_token', type='text', value=gitlab_token, autocorrection=False, autocapitalization=False), dict(title='Repo', key='gitlab_repo', type='text', value=gitlab_repo, autocorrection=False, autocapitalization=False) ] ) posting_fields = ( 'Post Settings', [ dict(title='Title', key='title', type='text', value=title), dict(title='Author', key='author', type='text', value=author), dict(title='Draft', key='draft', type='switch', value=True), dict(title='Layout', key='layout', type='text', value='post', autocorrection=False, autocapitalization=False), dict(title='Tags', key='tags', type='text', value=''), dict(title='Categories', key='categories', type='text', value=''), dict(title='Comments', key='comments', type='switch', value=True), dict(title='Excerpt', key='excerpt', type='text', value=''), dict(title='ImagePath', key='feature_img_path', type='text', value=''), dict(title='ImageWide', key='feature_img_wide', type='switch', value=False), dict(title='ImageCaption', key='feature_img_caption', type='text', value=''), dict(title='Filename', key='filename', type='text', value=filename, autocorrection=False, autocapitalization=False) ], 'Separate tags/categories with spaces' ) results = dialogs.form_dialog(title='publish new post', sections=[ posting_fields, gitlab_fields, dbx_fields ]) if results is None: console.hud_alert('posting was cancelled', 'error') return results['tags'] = process_string_array(results['tags']) results['categories'] = process_string_array(results['categories']) metas = { 'layout': results['layout'], 'author': results['author'], 'draft': results['draft'], 'tags': results['tags'], 'categories': results['categories'], 'comments': results['comments'], 'excerpt': results['excerpt'], 'feature_img_path': results['feature_img_path'], 'feature_img_wide': results['feature_img_wide'], 'feature_img_caption': results['feature_img_caption'], 'branch': 'master', 'filename': results['filename'] } if gitlab_token != results['gitlab_token']: keychain.set_password('gitlab_token', results['gitlab_user'], results['gitlab_token']) if dbx_token != results['dbx_token']: keychain.set_password('dbx_token', results['gitlab_user'], results['dbx_token']) console.show_activity() mb = MobileBlogger(results['gitlab_url'], results['gitlab_repo'], results['gitlab_token'], results['dbx_token']) mb.create_new_post(results['title'], text, metas) mb.git_sync_dropbox() console.hud_alert('new post created!') else: print('no input text found')
import StringIO import appex import console import json import keychain api_key = keychain.get_password('Project Oxford', 'Computer Vision API') if api_key == None: import clipboard api_key = console.input_alert('Insert your API key', '', str(clipboard.get())) if api_key == None: raise Exception('You need an API key.') else: keychain.set_password('Project Oxford', 'Computer Vision API', api_key) if appex.is_running_extension(): image = appex.get_image() else: image = photos.capture_image() if image == None: image = photos.pick_image(original=True) if image == None: raise Exception('You must select one image') enhancerColor = ImageEnhance.Color(image) image = enhancerColor.enhance(0.0) output = StringIO.StringIO()
def set_password(args): p = console.password_alert("Tradervue Credentials", args['user']) keychain.set_password(KEYCHAIN_ID, args['user'], p) return True
def main(): if not appex.is_running_extension(): print 'Running in Pythonista app, using test data...\n' text = ''' ''' else: text = appex.get_text() if text: author = 'Taha Dhiaeddine Amdouni' github_repo = 'tdamdouni.github.io' github_user = '******' github_password = keychain.get_password('github', github_user) or '' (title, text) = extract_title(text) filename = '%s-%s.md' % (date.today(), slug(title)) github_fields = ( 'Github Settings', [ dict(title='Github Username', key='github_user', type='text', value=github_user, autocorrection=False, autocapitalization=False), dict(title='Github Password', key='github_password', type='password', value=github_password), dict(title='Repository', key='github_repo', type='text', value=github_repo, autocorrection=False, autocapitalization=False) ] ) posting_fields = ( 'Post Settings', [ dict(title='Title', key='title', type='text', value=title), dict(title='Author', key='author', type='text', value=author), dict(title='Layout', key='layout', type='text', value='post', autocorrection=False, autocapitalization=False), dict(title='Tags', key='tags', type='text', value=''), dict(title='Filename', key='filename', type='text', value=filename, autocorrection=False, autocapitalization=False) ], 'Please seperate tags by spaces.' ) results = dialogs.form_dialog(title='Publish new post', sections=[ posting_fields, github_fields ]) if results is None: console.hud_alert('Posting was cancelled', 'error') return metas = { 'tags': results['tags'], 'branch': 'master', 'author': results['author'], 'layout': results['layout'], 'filename': results['filename'] } if github_password != results['github_password']: keychain.set_password('github', results['github_user'], results['github_password']) console.show_activity() mb = MobileBlogger(results['github_user'], results['github_password'], results['github_repo']) mb.create_new_post(results['title'], text, metas) console.hud_alert('New post created!') else: print 'No input text found.'
import sys import clipboard import keychain import console import api import webbrowser return_url = None if len(sys.argv) >= 2: return_url = sys.argv[1] api_key = keychain.get_password("linode", "api_key") if api_key == None: api_key = console.password_alert("Enter Linode API key") keychain.set_password("linode", "api_key", api_key) linode = api.Api(api_key) DATACENTER_ID = 2 PLAN_ID = 1 IMAGE_NAME = "dev image" NODE_LABEL = "dev01" NODE_GROUP = "Dev" DISK1_SIZE = 22000 DISK_SWAP_SIZE = 256 print "selecting kernel" kernel_id = 0 kernels = linode.avail_kernels(isKVM=1) for k in kernels:
import keychain import console get_or_set = console.alert('Get or set?','','Get','Set') if get_or_set == 1: service = console.input_alert('Service to get?') user = console.input_alert('What user?') mypass = keychain.get_password(service, user) if mypass == None: console.alert('Couldn\'t find that one.') else: copy_here = console.alert('Print, clipboard, or console?','','Print','Clipboard','Console') if copy_here == 1: console.clear() print(mypass) elif copy_here == 2: import clipboard clipboard.set(mypass) elif copy_here == 3: console.alert(mypass) elif get_or_set == 2: service = console.input_alert('Service name to store') user = console.input_alert('Username to store') mypass = console.input_alert('Password to store') keychain.set_password(service, user, mypass) console.alert('All done.')