def _authorization_code_request(config, auth_code): config = read_config() auth_key = get_auth_key(config.client_id, config.client_secret) headers = { 'Authorization': f'Basic {auth_key}', } options = { 'code': auth_code, 'redirect_uri': 'http://localhost:3000/callback', 'grant_type': 'authorization_code', 'json': True } response = requests.post(config.access_token_url, headers=headers, data=options) content = json.loads(response.content.decode('utf-8')) if response.status_code == 400: error_description = content.get('error_description', '') raise BadRequestError(error_description) access_token = content.get('access_token', None) token_type = content.get('token_type', None) expires_in = content.get('expires_in', None) scope = content.get('scope', None) refresh_token = content.get('refresh_token', None) return Authorization(access_token, token_type, expires_in, scope, refresh_token)
def home(): config = read_config() get_oauth_token(config) url = f'{config.authorize_url}?oauth_token={req_token.oauth_token}' return render_template('index.html', link=url)
def home(): config = read_config() get_oauth_token(config) url = "{}?oauth_token={}".format(config.authorize_url, req_token.oauth_token) return render_template("index.html", link=url)
def callback(): config = read_config() code = request.args.get('code', '') response = _authorization_code_request(config, code) file = open('.pytify', mode='w', encoding='utf-8') file.write(response.refresh_token) file.close() return 'All set! You can close the browser window and stop the server.'
def home(): config = read_config() params = { 'client_id': config.client_id, 'response_type': 'code', 'redirect_uri': 'http://localhost:3000/callback', 'scope': 'user-read-private user-modify-playback-state', } enc_params = urlencode(params) url = f'{config.auth_url}?{enc_params}' return render_template('index.html', link=url)
def callback(): global req_token global consumer config = read_config() oauth_verifier = request.args.get("oauth_verifier", "") token = oauth.Token(req_token.oauth_token, req_token.oauth_token_secret) token.set_verifier(oauth_verifier) client = oauth.Client(consumer, token) _, content = client.request(config.access_token_url, "POST") access_token = dict(parse_qsl(content.decode("utf-8"))) with open(".twitterauth", "w") as req_auth: file_content = yaml.dump(access_token, default_flow_style=False) req_auth.write(file_content) return "All set! You can close the browser window and stop the server."
def test_basic(self): file = """name: YuviSense theme: simpl links: - name: Stats blog url: http://thestatbot.com - name: Scoble url: http://scobleizer.com""" conf = core.read_config(StringIO(file)) self.assertEqual(len(conf), 3) self.assertEqual(conf["name"], "YuviSense") self.assertEqual(conf["theme"], "simpl") self.assertEqual(len(conf["links"]), 2) self.assertEqual(conf["links"][0]["name"], "Stats blog") self.assertEqual(conf["links"][0]["url"], "http://thestatbot.com") self.assertEqual(conf["links"][1]["name"], "Scoble") self.assertEqual(conf["links"][1]["url"], "http://scobleizer.com")
def test_basic(self): file = """name: YuviSense theme: simpl links: - name: Stats blog url: http://thestatbot.com - name: Scoble url: http://scobleizer.com""" conf = core.read_config(StringIO(file)) self.assertEqual(len(conf), 3) self.assertEqual(conf['name'], 'YuviSense') self.assertEqual(conf['theme'], 'simpl') self.assertEqual(len(conf['links']), 2) self.assertEqual(conf['links'][0]['name'], 'Stats blog') self.assertEqual(conf['links'][0]['url'], 'http://thestatbot.com') self.assertEqual(conf['links'][1]['name'], 'Scoble') self.assertEqual(conf['links'][1]['url'], 'http://scobleizer.com')
def backup(config): """ Given a configuration file with files and directories, backup the files to the directories. Args: config: Optional configuration file, defaults to `config.json` """ click.echo("Starting backup") valid, cfg = read_config(config) if not valid: click.echo("Invalid configuration file {}".format(config)) sys.exit(1) valid, errors = validate_user_input(cfg["sources"], cfg["destinations"]) if not valid: for error in errors: click.echo(error) sys.exit(1) backup_files(cfg["sources"], cfg["destinations"]) click.echo("Backup complete") sys.exit(0)
def test_read_config_get_token(): c = read_config() get_oauth_token(c)