def request_access_token(): """ Request an Access Token and Access Token Secret """ consumer_key, consumer_secret = load_api_key() client_config = upwork.Config({ 'consumer_key': consumer_key, 'consumer_secret': consumer_secret }) client = upwork.Client(client_config) try: client_config.access_token client_config.access_token_secret except AttributeError: verifier = input( f'Please enter the verification code you get ' f'following this link:\n{client.get_authorization_url()}\n\n>' ) print('Retrieving keys.... ') # Once you receive the request token and the resource owner's authorization # (verifier code), you are ready to request Upwork Server an Access token access_token, access_token_secret = client.get_access_token(verifier) print('OK') with open(config.ACCESS_TOKEN_FILENAME, "w") as f: f.write(access_token+"\n") f.write(access_token_secret) return [access_token, access_token_secret]
def get_tokens(): with open('keys.json', 'r') as json_file: config = json.load(json_file) client = upwork.Client(upwork.Config(config)) token = client.get_request_token() print(token) verifier = input('Please enter the verification code you get ' 'following this link:\n{0}\n\n> '.format( client.get_authorization_url())) access_token, access_token_secret = client.get_access_token(verifier) print(access_token, access_token_secret)
def get_desktop_client(): """Emulation of desktop app. Your keys should be created with project type "Desktop". Returns: ``upwork.Client`` instance ready to work. """ print("Emulating desktop app") consumer_key = input("Please enter consumer key: > ") consumer_secret = input("Please enter key secret: > ") config = upwork.Config({ "client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "client_secret": "xxxxxxxxxxxxx", "redirect_uri": "https://a.callback.url", }) # If token data already known and saved, you can reuse them # by adding 'token' parameter to the config # token = {'access_token': 'xxxxxxxxxxxxxxxxxx', 'expires_at': 1590479276.547947, 'expires_in': '86400', 'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxx', 'token_type': 'Bearer'} # config = upwork.Config({'client_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'client_secret': 'xxxxxxxxxxxxx', 'token': token}) client = upwork.Client(config) try: config.token except AttributeError: authorization_url, state = client.get_authorization_url() # cover "state" flow if needed authz_code = input( "Please enter the full callback URL you get " "following this link:\n{0}\n\n> ".format(authorization_url)) print("Retrieving access and refresh tokens.... ") token = client.get_access_token(authz_code) # WARNING: the access token will be refreshed automatically for you # in case it's expired, i.e. expires_at < time(). Make sure you replace the # old token accordingly in your security storage. Call client.get_actual_config # periodically to sync-up the data pprint(token) print("OK") # For further use you can store ``token`` data somewhere return client
def get_desktop_client(): """Emulation of a desktop application. Your key should be created with the project type "Desktop". Returns: ``upwork.Client`` instance ready to work. """ print("Emulating desktop app") consumer_key = input('Please enter consumer key: > ') consumer_secret = input('Please enter key secret: > ') config = upwork.Config({ 'consumer_key': consumer_key, 'consumer_secret': consumer_secret }) """Assign access_token and access_token_secret if they are known config = upwork.Config({\ 'consumer_key': 'xxxxxxxxxxx',\ 'consumer_secret': 'xxxxxxxxxxx',\ 'access_token': 'xxxxxxxxxxx',\ 'access_token_secret': 'xxxxxxxxxxx'}) """ client = upwork.Client(config) try: config.access_token config.access_token_secret except AttributeError: verifier = input('Please enter the verification code you get ' 'following this link:\n{0}\n\n> '.format( client.get_authorization_url())) print('Retrieving keys.... ') access_token, access_token_secret = client.get_access_token(verifier) print('OK') # For further use you can store ``access_toket`` and # ``access_token_secret`` somewhere return client
def download(): try: api_key, api_key_secret = load_api_key() except CredentialsNotFoundError as e: import os return jsonify({'msg': os.listdir("./data")}) access_token, access_token_secret = load_access_token() client_config = upwork.Config({ 'consumer_key': api_key, 'consumer_secret': api_key_secret, 'access_token': access_token, 'access_token_secret': access_token_secret }) client = upwork.Client(client_config) jobs = search_jobs(client, SEARCH_TERMS) add_records(jobs) return jsonify({'msg': "Done"})
def get_metadata(client, type): """ https://developers.upwork.com/?lang=python#metadata """ if type == "categories": return metadata.Api(client).get_categories_v2() elif type == "skills": return metadata.Api(client).get_skills_v2() elif type == "specialties": # try client.get("/profiles/v1/metadata/specialties") return metadata.Api(client).get_specialties() if __name__ == "__main__": api_key, api_key_secret = load_api_key() access_token, access_token_secret = load_access_token() client_config = upwork.Config({ 'consumer_key': api_key, 'consumer_secret': api_key_secret, 'access_token': access_token, 'access_token_secret': access_token_secret }) client = upwork.Client(client_config) jobs = search_jobs(client, SEARCH_TERMS) add_records(jobs)
parser = argparse.ArgumentParser() parser.add_argument("--api-key", help="API Key", required=True) parser.add_argument("--api-secret", help="API Secret", required=True) parser.add_argument("--month", help="YYYY-MM format", required=True) parser.add_argument("--path", help="Reports path", required=True) parser.add_argument("--access-token", help="Access token", required=False) parser.add_argument("--access-token-secret", help="Access token secret", required=False) args = parser.parse_args() if args.access_token is not None and args.access_token_secret is not None: client = upwork.Client( upwork.Config({ "consumer_key": args.api_key, "consumer_secret": args.api_secret, "access_token": args.access_token, "access_token_secret": args.access_token_secret, })) else: client = upwork.Client( upwork.Config({ "consumer_key": args.api_key, "consumer_secret": args.api_secret })) verifier = input("Please enter the verification code you get " "following this link:\n{0}\n\n> ".format( client.get_authorization_url())) access_token, access_token_secret = client.get_access_token(verifier) print(f"Generated tokens: {access_token}, {access_token_secret}") client = upwork.Client( upwork.Config({