示例#1
0
def has_uniflow_printer(token):
    """Returns True if the user has the Calvin uniFLOW printer installed
    on their Google account, and False otherwise.

        Params:
    token - oauth token.
    """
    # for use with 'fakeoauth.py' testing utility
    if token == 'fakeoauth.py':
        return True
    if token == 'fakeoauth.py|noprinter':
        return False

    oauth = auth.OAuth2(access_token=token, token_type='Bearer')
    printers = client.list_printers(auth=oauth)['printers']
    for printer in printers:
        id = printer.get('id')
        if id == UNIFLOW_ID:
            return True
    return False
示例#2
0
def submit_job(token,
               file,
               color=False,
               duplex=False,
               copies=1,
               collate=True,
               staple=False):
    """Submits a print job to the uniFLOW printer.

    Token is an oauth token.
    File is a file-like object to be printed.
    Duplex means double sided.
    """
    file_name = os.path.basename(file.name)
    content = [file_name, file]
    oauth = auth.OAuth2(access_token=token, token_type='Bearer')
    print_ticket = _make_print_ticket(color=color,
                                      duplex=duplex,
                                      copies=copies,
                                      collate=collate,
                                      staple=staple)
    try:
        job = client.submit_job(printer=UNIFLOW_ID,
                                content=content,
                                ticket=print_ticket,
                                auth=oauth)
    except client.PrintingError as err:
        raise JobSubmissionError(err)

    if job.get('success', False) == False:
        raise JobSubmissionError('Error submitting the print job to Google.')

    try:
        job_id = job['job']['id']
    except KeyError as err:
        raise JobSubmissionError(err)

    _wait_for_job_processing(auth=oauth, job_id=job_id)
示例#3
0
    print "%d tweets found:" % len(ret)
    for status in ret:
        print "%s === (%s)\n" % (status.text, status.author.screen_name)


def general_test(client, api_name):
    ret = getattr(client, api_name)()
    if (isinstance(ret, list)):
        ret = ret[0]
    for k in dir(ret):
        print "%s:%s" % (k, getattr(ret, k))


callback_uri = "http://var.grampro.com/echo"

auth_handler = auth.OAuth2()

if len(sys.argv) > 1:
    print "go to:\n" + auth_handler.get_authorize_url(callback_uri)
    code = raw_input("Input the access code:\n")
    token = auth_handler.request_access_token(code, callback_uri)
    print "access token:\n" + str(token)
    auth_handler.set_access_token(token['access_token'], 2000000000)
else:
    auth_handler.set_access_token('2.00FcT8EC0SW1Iebc1f789915BNrQ9C',
                                  2000000000)

client = api.API(auth_handler)

for api_name in api_list:
    if api_list[api_name] == 1: