Exemplo n.º 1
0
def time_reports(public_key, secret_key):
    print "Emulating web-based app"
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print "Please to this URL (authorize the app if necessary):"
    print client.auth.auth_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter"
    frob = raw_input('Enter frob: ') 
    auth_token, user = client.auth.get_token(frob)
    print "Authenticated user:"
    print user
    #Instantiating a new client, now with a token. 
    #Not strictly necessary here (could just set `client.auth_token`), but 
    #typical for web apps, which wouldn't probably keep client instances 
    #between requests
    client = odesk.Client(public_key, secret_key, auth_token)
    print client.time_reports.get_provider_report('user1', 
                    odesk.Query(select=odesk.Query.DEFAULT_TIMEREPORT_FIELDS, 
                    where=(odesk.Q('worked_on') <= date.today()) &\
                     (odesk.Q('worked_on') > '2010-05-01')))

    print client.time_reports.get_provider_report('user1', 
                    odesk.Query(select=odesk.Query.DEFAULT_TIMEREPORT_FIELDS, 
                    where=(odesk.Q('worked_on') <= date.today()) &\
                     (odesk.Q('worked_on') > '2010-05-01')), hours=True)

    print client.time_reports.get_agency_report('company1', 'agency1', 
                    odesk.Query(select=odesk.Query.DEFAULT_TIMEREPORT_FIELDS, 
                    where=(odesk.Q('worked_on') <= date.today()) &\
                     (odesk.Q('worked_on') > '2010-05-01')), hours=True)
Exemplo n.º 2
0
def desktop_app():
    """Emulation of desktop app.
    Your keys should be created with project type "Desktop".

    Returns: ``odesk.Client`` instance ready to work.

    """
    print "Emulating desktop app"

    public_key = raw_input('Please enter public key: > ')
    secret_key = raw_input('Please enter secret key: > ')

    client = odesk.Client(public_key, secret_key)
    verifier = raw_input('Please enter the verification code you get '
                         'following this link:\n{0}\n\n> '.format(
                             client.auth.get_authorize_url()))

    print 'Retrieving keys.... '
    access_token, access_token_secret = client.auth.get_access_token(verifier)
    print 'OK'

    # For further use you can store ``access_toket`` and
    # ``access_token_secret`` somewhere
    client = odesk.Client(public_key,
                          secret_key,
                          oauth_access_token=access_token,
                          oauth_access_token_secret=access_token_secret)
    return client
Exemplo n.º 3
0
    def authorize(self):
        # for details go to https://developers.odesk.com/?lang=python#authentication_oauth-10
        client = odesk.Client(public_key=self.app_key,
                              secret_key=self.app_secret)

        # 1. Get request token
        request_token, request_token_secret = client.auth.get_request_token()
        print 'Received request_token:', request_token, ', request_token_secret:', request_token_secret

        # 2. Authorize and get verifier
        # Browser
        br = mechanize.Browser()
        self.login_to_odesk(client, br)
        verifier = self.get_verifier(client, br)

        # 3. Get access token
        access_token, access_token_secret = client.auth.get_access_token(
            verifier)

        # 4. update and save new tokens
        if access_token and access_token_secret:
            client = odesk.Client(
                public_key=self.app_key,
                secret_key=self.app_secret,
                oauth_access_token=access_token,
                oauth_access_token_secret=access_token_secret,
                fmt='json')
            self.access_token = access_token
            self.access_token_secret = access_token_secret
            return client
        return
Exemplo n.º 4
0
def provider(public_key, secret_key):
    print("Emulating web-based app")
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print("Please to this URL (authorize the app if necessary):")
    print(client.auth.auth_url())
    print("After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter")
    frob = input('Enter frob: ')
    auth_token, user = client.auth.get_token(frob)
    print("Authenticated user:"******"Search providers:")
    print(client.provider.get_providers({'q': 'python'}))
    print("Search jobs:")
    print(client.provider.get_jobs({'q': 'wowza'}))
    print("Provider all:")
    #someref is like 71de2d463c748623
    print(client.provider.get_provider('~~someref'))
    print("Provider brief:")
    print(client.provider.get_provider_brief('~~someref'))
    print("Revoke access")
    print(client.auth.revoke_token())
Exemplo n.º 5
0
def hr_post_job(public_key, secret_key):
    print("Emulating web-based app")
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print("Please to this URL (authorize the app if necessary):")
    print(client.auth.auth_url())
    print("After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter")
    frob = input('Enter frob: ')
    auth_token, user = client.auth.get_token(frob)
    print("Authenticated user:"******"Exception at %s %s" % (client.last_method, client.last_url))
        raise e
def web_based_app():
    # Enter your public and secret key below
    public_key = ''
    secret_key = ''

    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)

    print "Please go to this URL (authorize the app if necessary):"
    print client.auth.get_authorize_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?oauth_verifier= parameter"

    verifier = raw_input('Enter oauth_verifier: ')

    oauth_access_token, oauth_access_token_secret = \
        client.auth.get_access_token(verifier)

    # Instantiating a new client, now with a token.
    # Not strictly necessary here (could just set `client.oauth_access_token`
    # and `client.oauth_access_token_secret`), but typical for web apps,
    # which wouldn't probably keep client instances between requests
    client = odesk.Client(public_key,
                          secret_key,
                          oauth_access_token=oauth_access_token,
                          oauth_access_token_secret=oauth_access_token_secret)

    return client
Exemplo n.º 7
0
def oconomy(public_key, secret_key):
    print "Emulating web-based app"
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print "Please to this URL (authorize the app if necessary):"
    print client.auth.auth_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter"
    frob = raw_input('Enter frob: ')
    auth_token, user = client.auth.get_token(frob)
    print "Authenticated user:"******"monthly summary"
    print client.oconomy.get_monthly_summary('201011')
    print "hours worked by locations"
    print client.oconomy.get_hours_worked_by_locations()
    print "hours worked by weeks"
    print client.oconomy.get_hours_worked_by_weeks()
    print "top countries by hours"
    print client.oconomy.get_top_countries_by_hours()
    print "earnings by categories"
    print client.oconomy.get_earnings_by_categories()
    print "most requested skills"
    print client.oconomy.get_most_requested_skills()
Exemplo n.º 8
0
def web_based_app():
    """Emulation of web-based app.
    Your keys should be created with project type "Web".

    Returns: ``odesk.Client`` instance ready to work.

    """
    print "Emulating web-based app"

    public_key = raw_input('Please enter public key: > ')
    secret_key = raw_input('Please enter secret key: > ')

    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)

    print "Please to this URL (authorize the app if necessary):"
    print client.auth.get_authorize_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?oauth_verifier= parameter"

    verifier = raw_input('Enter oauth_verifier: ')

    oauth_access_token, oauth_access_token_secret = \
        client.auth.get_access_token(verifier)

    # Instantiating a new client, now with a token.
    # Not strictly necessary here (could just set `client.oauth_access_token`
    # and `client.oauth_access_token_secret`), but typical for web apps,
    # which wouldn't probably keep client instances between requests
    client = odesk.Client(public_key,
                          secret_key,
                          oauth_access_token=oauth_access_token,
                          oauth_access_token_secret=oauth_access_token_secret)

    return client
Exemplo n.º 9
0
def web_based_app(public_key, secret_key):
    print("Emulating web-based app")
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key, auth='oauth')
    print("Please to this URL (authorize the app if necessary):")
    #import pdb
    #pdb.set_trace()
    print(client.auth.get_authorize_url())
    print ("After that you should be redirected back to your app URL with " + \
          "additional ?oauth_verifier= parameter")
    verifier = input('Enter oauth_verifier: ')
    oauth_access_token, oauth_access_token_secret = client.auth.get_access_token(
        verifier)
    #import pdb
    #pdb.set_trace()
    #Instantiating a new client, now with a token.
    #Not strictly necessary here (could just set `client.oauth_access_token`
    #and `client.oauth_access_token_secret`), but typical for web apps,
    #which wouldn't probably keep client instances between requests
    client = odesk.Client(public_key,
                          secret_key,
                          auth='oauth',
                          oauth_access_token=oauth_access_token,
                          oauth_access_token_secret=oauth_access_token_secret)

    try:
        print("Team rooms:")
        print(client.team.get_teamrooms())
        #HRv2 API
        print("HR: companies")
        print(client.hr.get_companies())
        print("HR: teams")
        print(client.hr.get_teams())
        print("HR: offers")
        print(client.hr.get_offers())
        print("HR: get_engagements")
        print(client.hr.get_engagements())
        print("HR: userroles")
        print(client.hr.get_user_role())
        print("HR: candidacy stats")
        print(client.hr.get_candidacy_stats())
        print("Get jobs")
        print(client.provider.get_jobs({'q': 'python'}))
        print("Financial: withdrawal methods")
        print(client.finance.get_withdrawal_methods())
    except Exception as e:
        print("Exception at %s %s" % (client.last_method, client.last_url))
        raise e
Exemplo n.º 10
0
    def check(self):
        # 3 atempts to get acess tokens and create odesk clint
        for a in range(3):
            # if we have all tokens - just create oDesk Client
            if self.access_token and self.access_token_secret:
                client = odesk.Client(
                    public_key=self.app_key,
                    secret_key=self.app_secret,
                    oauth_access_token=self.access_token,
                    oauth_access_token_secret=self.access_token_secret,
                    fmt='json')
            else:  #else we have to login and get access tokens
                client = self.authorize()

            if not client: continue

            # get jobs from oDesk:
            try:
                jobs = self.search_jobs(client)
            except RuntimeError, err:
                print 'Error while searching jobs on oDesk:', err
                continue

            if not jobs: continue

            jobs_filtered = self.filter_date_created(jobs)
            if not self.jobs_filtered: continue
            else: return True
Exemplo n.º 11
0
def odesk_login(request):
    client = odesk.Client(
        settings.ODESK_SERVER_KEY,
        settings.ODESK_SERVER_SECRET,
        auth='oauth',
    )
    request.session['odesk_client'] = client
    return redirect(client.auth.get_authorize_url())
Exemplo n.º 12
0
def provider(public_key, secret_key):
    print "Emulating web-based app"
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print "Please to this URL (authorize the app if necessary):"
    print client.auth.auth_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter"
    frob = raw_input('Enter frob: ') 
    auth_token, user = client.auth.get_token(frob)
    print "Authenticated user:"******"Provider skills:"
    print client.provider.get_skills('~~someref')
    # add new skill
    print "Adding provider skill"
    print client.provider.add_skill('~~someref', {'skill':'skill'})
    # update a skill by giving a skill_id and new data
    print "Updating provider skill"
    print client.provider.update_skill('~~someref', 123, {'skill':'skill'})
    # delete a skill by giving a skill_id
    print "Deleting provider skill"
    print client.provider.delete_skill('~~someref', 123)
    # get quickinfo
    print "Get quick info"
    print client.provider.get_quickinfo('~~someref')
    # update a quickinfo by giving new data
    client.provider.update_quickinfo('~~someref', {'skill':'skill'})
    print client.provider.get_affiliates('someref')
    print "Get categories metadata:"
    print client.provider.get_categories_metadata()
    print "Get skills metadata:"
    print client.provider.get_skills_metadata()
    print "Get regions metadata:"
    print client.provider.get_regions_metadata()
    print "Get tests metadata:"
    print client.provider.get_tests_metadata()
    print "Revoke access"
    print client.auth.revoke_token()
Exemplo n.º 13
0
def web_based_app(public_key, secret_key):
    print ("Emulating web-based app")
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key, auth='oauth')

    print ("Please to this URL (authorize the app if necessary):")
    print (client.auth.get_authorize_url())

    print ("After that you should be redirected back to your app URL with " + \
          "additional ?oauth_verifier= parameter")
    verifier = input('Enter oauth_verifier: ')

    oauth_access_token, oauth_access_token_secret = client.auth.get_access_token(verifier)

    #Instantiating a new client, now with a token.
    #Not strictly necessary here (could just set `client.oauth_access_token`
    #and `client.oauth_access_token_secret`), but typical for web apps,
    #which wouldn't probably keep client instances between requests

    client = odesk.Client(public_key, secret_key, auth='oauth',
                        oauth_access_token=oauth_access_token,
                        oauth_access_token_secret=oauth_access_token_secret)

    try:
        print ("Tasks list:")
        print (client.task.get_user_tasks('company_id', 'team_id', 'user_id'))
        #Post new task
        print(client.task.post_user_task(company_id='company',
                team_id='team', user_id='provider', code='TEST_TASK',
                description='Test api task', url='http://task_url.py'
            ))
        #Update task
        print(client.task.post_user_task(company_id='company',
                team_id='team', user_id='provider', code='TEST_TASK',
                description='Test api updated', url='http://task_url.py'
            ))
        #Should be list of task_codes. If one task list of 1 element
        print(client.task.delete_user_task(company_id='company',
                team_id='team', user_id='provider', task_codes=["TEST_TASK", "TASK_2"]
            ))

    except Exception as e:
        print ("Exception at %s %s" % (client.last_method, client.last_url))
        raise e
Exemplo n.º 14
0
def web_based_app(public_key, secret_key):
    print "Emulating web-based app"
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print "Please to this URL (authorize the app if necessary):"
    print client.auth.auth_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter"
    frob = raw_input('Enter frob: ')
    auth_token, user = client.auth.get_token(frob)
    print "Authenticated user:"******"Team rooms:"
        print client.team.get_teamrooms()
        #HRv2 API
        print "HR: companies"
        print client.hr.get_companies()
        print "HR: teams"
        print client.hr.get_teams()
        print "HR: offers"
        print client.hr.get_offers()
        print "HR: get_engagements"
        print client.hr.get_engagements()
        print "HR: userroles"
        print client.hr.get_user_role()
        print "HR: candidacy stats"
        print client.hr.get_candidacy_stats()
        print "Get jobs"
        print client.provider.get_jobs({'q': 'python'})
        print "Financial: withdrawal methods"
        print client.finance.get_withdrawal_methods()
        print "Revoke access"
        print client.auth.revoke_token()
    except Exception, e:
        print "Exception at %s %s" % (client.last_method, client.last_url)
        raise e
Exemplo n.º 15
0
def user_snapshots(public_key, secret_key):
    print "Emulating web-based app"
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print "Please to this URL (authorize the app if necessary):"
    print client.auth.auth_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter"
    frob = raw_input('Enter frob: ') 
    auth_token, user = client.auth.get_token(frob)
    print "Authenticated user:"
    print user
    #Instantiating a new client, now with a token. 
    #Not strictly necessary here (could just set `client.auth_token`), but 
    #typical for web apps, which wouldn't probably keep client instances 
    #between requests
    client = odesk.Client(public_key, secret_key, auth_token)
    print client.team.get_snapshot('company1', 'user1')
	print client.team.update_snapshot('company1', 'user1', memo='Updated Memo')
	print client.team.delete_snapshot('company1', 'user1', datetime=datetime.utcnow())
Exemplo n.º 16
0
def make_odesk_client(token, secret, test=False):
    if test:
        return make_test_client(token, secret)

    return odesk.Client(
        settings.ODESK_SERVER_KEY,
        settings.ODESK_SERVER_SECRET,
        oauth_access_token=token,
        oauth_access_token_secret=secret,
        auth='oauth',
    )
Exemplo n.º 17
0
    def jobs_search(self):
        client = odesk.Client(
            public_key,
            secret_key,
            oauth_access_token=oauth_access_token,
            oauth_access_token_secret=oauth_access_token_secret)

        jobs = self.get_jobs_list(client=client,
                                  jobs_parameter=job_search_parameter)

        return jobs
Exemplo n.º 18
0
def make_test_client(token=None, secret=None, *args, **kwargs):
    """
        Returns server-authenticated oDesk client.
    """
    return odesk.Client(
        settings.ODESK_SERVER_KEY,
        settings.ODESK_SERVER_SECRET,
        oauth_access_token=settings.ODESK_SERVER_TOKEN_KEY,
        oauth_access_token_secret=settings.ODESK_SERVER_TOKEN_SECRET,
        auth='oauth',
    )
Exemplo n.º 19
0
def simple_messager(public_key, secret_key):
    print("Emulating web-based app")
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print("Please to this URL (authorize the app if necessary):")
    print(client.auth.auth_url())
    print("After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter")
    frob = input('Enter frob: ')
    auth_token, user = client.auth.get_token(frob)
    print("Authenticated user:")
    print(user)
    #Instantiating a new client, now with a token.
    #Not strictly necessary here (could just set `client.auth_token`), but
    #typical for web apps, which wouldn't probably keep client instances
    #between requests
    client = odesk.Client(public_key, secret_key, auth_token)
    print(client.mc.get_trays())
    #print(client.mc.get_tray_content('my_username', 'inbox'))
    #print(client.mc.get_thread_content('my_username', '111111'))
    print(client.mc.post_message('sender', 'recipient', 'test from api', 'test body'))
Exemplo n.º 20
0
def fin_reports(public_key, secret_key):
    print "Emulating web-based app"
    #Instantiating a client without an auth token
    client = odesk.Client(public_key, secret_key)
    print "Please to this URL (authorize the app if necessary):"
    print client.auth.auth_url()
    print "After that you should be redirected back to your app URL with " + \
          "additional ?frob= parameter"
    frob = raw_input('Enter frob: ') 
    auth_token, user = client.auth.get_token(frob)
    print "Authenticated user:"
    print user
    #Instantiating a new client, now with a token. 
    #Not strictly necessary here (could just set `client.auth_token`), but 
    #typical for web apps, which wouldn't probably keep client instances 
    #between requests
    client = odesk.Client(public_key, secret_key, auth_token)
    print client.finreports.get_provider_billings('1111',  
                    odesk.Query(select=['date', 'type',
                                        'amount'], 
                    where=((odesk.Q('date') <= date.today()))))
def api_authorization():

    print """
        Use 
        https://www.odesk.com/services/api/keys
        for getting API keys for your app.
        It can take up to 24 hours to get your keys.
        Use "desktop" application type for your API keys request.
        """

    public_key = raw_input('Please enter public key ("Key" field): > ')
    secret_key = raw_input('Please enter secret key ("Secret" field): > ')

    try:
        client = odesk.Client(public_key, secret_key)
        verifier = raw_input(
            '\nPlease enter the verification code you get '
            'following this link:\n{0}\n'
            'You should be logged in as application user\n> '.format(
                client.auth.get_authorize_url()))
    except Exception, e:
        print "Something went wrong, please check entered keys"
        return
Exemplo n.º 22
0
def odesk_complete(request):
    client = request.session['odesk_client']
    token, secret = client.auth.get_access_token(request.GET['oauth_verifier'])
    client = odesk.Client(
        settings.ODESK_SERVER_KEY,
        settings.ODESK_SERVER_SECRET,
        oauth_access_token=token,
        oauth_access_token_secret=secret,
        auth='oauth',
    )
    info = client.hr.get_user('me')
    cipher = info['profile_key']

    if request.user.is_authenticated():
        if request.user.get_profile().odesk_uid == '':
            request.user.get_profile().odesk_id = info['id']
            request.user.get_profile().odesk_uid = cipher
            request.user.get_profile().odesk_token = token
            request.user.get_profile().odesk_secret = secret
            request.user.get_profile().save()

            send_event("EventNewOdeskAssoc", user_id=request.user.id)
            # Add Worker model on odesk account association
            if not Worker.objects.filter(external_id=cipher):
                w = Worker.objects.create_odesk(external_id=cipher)
                request.user.get_profile().worker_entry = w
                request.user.get_profile().save()
            request.session['success'] = 'You have successfully logged in.'
        return redirect('index')
    else:
        try:
            assoc = Account.objects.get(odesk_uid=cipher)
            u = authenticate(username=assoc.user.username, password='******')
            if not u:
                request.session['error'] = 'Such account already exists.'
                return redirect('login')
            login(request, u)
            return redirect('index')
        except Account.DoesNotExist:
            u = User.objects.create_user(email=info['email'],
                                         username='******'.join(['odesk', cipher]),
                                         password='******')
            profile = u.get_profile()
            profile.odesk_id = info['id']
            profile.odesk_uid = cipher
            profile.odesk_token = token
            profile.odesk_secret = secret
            send_event("EventNewOdeskAssoc", user_id=u.id)
            profile.full_name = '%s %s' % (info['first_name'],
                                           info['last_name'])
            profile.save()
            u = authenticate(username=u.username, password='******')
            login(request, u)

            # Create Worker model on odesk account registration
            if not Worker.objects.filter(external_id=cipher):
                w = Worker.objects.create_odesk(external_id=cipher)
                u.get_profile().worker_entry = w
                u.get_profile().save()
            request.session['success'] = 'You have successfuly registered'
            return redirect('settings')
                client.auth.get_authorize_url()))
    except Exception, e:
        print "Something went wrong, please check entered keys"
        return

    print 'Getting tokens'

    try:
        access_token, access_token_secret = client.auth.get_access_token(
            verifier)
    except Exception, e:
        print "Something went wrong, please check verification code is correct"
        return

    try:
        client = odesk.Client(public_key,
                              secret_key,
                              oauth_access_token=access_token,
                              oauth_access_token_secret=access_token_secret)
    except Exception, e:
        print "Something went wrong, looks like tokens aren't ok, check them"
        return

    print 'Use following information for API usage:'
    print 'oauth_access_token: "{0}"'.format(access_token)
    print 'oauth_access_token_secret: "{0}"'.format(access_token_secret)


if __name__ == '__main__':
    client = api_authorization()