예제 #1
0
파일: main.py 프로젝트: tsinclair/PyDeskAPI
    # Put together keyword argument list for find_app_auth()
    kwargs = {'app_name': pgm,             # name of this executable 
              'app_alias': alias,          # --name alias 
              'app_auth': auth,            # --app_auth file
              'auth_envar': 'ODESK_AUTH'}  # environment variable 

    auth = find_app_auth(**kwargs)
    if not auth:
        stderr('No authorization file found.\n')
        exit(1)

    kwargs = {'app_auth_file': auth}
    if alias: kwargs['app_alias'] = alias
    try:
        api = oDeskAPI(config=config, **kwargs)
    except AppInitError, e:
        stderr(e)
        stderr("Failed to initialize oDeskAPI instance...\n")
        exit(1)

    if popts['debug']: api.debug = True

    init_logging(api, popts)
    # Authorize this process with odesk.com developer API
    if not api.authorize():
        assert api.api_token == None
        log.error('failed to authorize client-- no api token')
        api.clean_exit(1)
    log.debug("app_main() returning {0!s}".format(argv2))
    return (api, argv2)
예제 #2
0
(pgm, ext) = path.splitext(path.basename(sys.argv[0]))
try:
    (popts, args) = parseargs(pgm, sys.argv[1:], usage)
except AppInitError, e:
    stderr(e)
    exit(1)

if not len(args) == 2:
    stderr ("\n  ** Need reference_no and amount, in that order **.\n")
    exit(usage(pgm, 1))

auth = '/home/tsinclair/archive/auth/auth.txt'
kwargs = {'app_auth_file': auth}

try:
    api = oDeskAPI(config=None, **kwargs)
except AppInitError, e:
    stderr("Failed to obtain oDeskAPI instance...\n")
    exit(1)

if not api.authorize():
    assert api.api_token == None
    log.error('failed to authorize client-- no api token')
    api.clean_exit(1)

ref = args[0]
bonus = args[1]
notes = '{0:s}: ${1:s}'.format(ref, bonus)
comment = 'Thank You!'
print ref, bonus, notes
#api.clean_exit(0)