Пример #1
0
def log_unknown_rfid(rfid):
    log.info("logging unknown rfid [%s]" % rfid)
    client, spread_key = get_client()
    sheets = worksheet_dict(client.get_worksheets(spread_key))
    worksheet_id = sheets['unknown']
    entry = gdata.spreadsheets.data.ListEntry()
    entry.set_value('rfid', rfid)
    entry.set_value('date', str(datetime.now()))
    client.add_list_entry(entry, spread_key, worksheet_id)
Пример #2
0
def fetch_tools():
    log.debug("fetching tools")
    client, spread_key = get_client()
    sheets = worksheet_dict(client.get_worksheets(spread_key))
    worksheet_id = sheets['tools']
    all_tools = []
    for entry in client.get_list_feed(spread_key, worksheet_id).entry:
        all_tools.append(entry.to_dict())
    log.info("fetched %d tools" % len(all_tools))
    with open(get_tools_file(), 'w') as fh:
        json.dump(all_tools, fh)
Пример #3
0
def log_time(tool, time, name, rfid):
    log.info("logging %s on %s for user %s [%s]" % (time, tool, name, rfid))
    client, spread_key = get_client()
    sheets = worksheet_dict(client.get_worksheets(spread_key))
    try:
        worksheet_id = sheets[tool]
    except KeyError:
        log.error("no such tool in spreadsheet")
        exit(1)

    entry = gdata.spreadsheets.data.ListEntry()
    entry.set_value('rfid', rfid)
    entry.set_value('name', name)
    entry.set_value('date', str(datetime.now()))
    entry.set_value('time', time)
    client.add_list_entry(entry, spread_key, worksheet_id)
Пример #4
0
credentials = credential_storage.get()

if credentials == None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage)

client = gdata.spreadsheets.client.SpreadsheetsClient()
token = gdata.gauth.OAuth2Token(client_id=flow.client_id, 
                                client_secret=flow.client_secret, 
                                scope=flow.scope,
                                user_agent="chisubmit", 
                                access_token=credentials.access_token, 
                                refresh_token=credentials.refresh_token)
token.authorize(client)

# Open spreadsheet
worksheets = client.get_worksheets(SPREADSHEET_KEY)

# Get first worksheet
worksheet_id = worksheets.entry[0].get_worksheet_id()

feed = client.get_list_feed(SPREADSHEET_KEY, worksheet_id)

for row in feed.entry:
    print "============================================"
    group = row.to_dict()

    if course.teams.has_key(group[GROUPNAME]):
        print "Skipping '%s'. Already exists." % group[GROUPNAME] 
        continue
    
    print "Adding group '%s'" % group[GROUPNAME]
Пример #5
0
time.sleep(1)

code = raw_input('Enter verification code: ').strip()
new_token = token.get_access_token(code)


client = gdata.spreadsheets.client.SpreadsheetsClient(source=USER_AGENT)
client = new_token.authorize(client)

feed = client.get_spreadsheets()

# XXX: Somehow pick the correct spreadsheet
sheet = feed.entry[0]
key = sheet.get_spreadsheet_key()
worksheets = client.get_worksheets(key)
sheet_id = worksheets.CellEntry[0].get_worksheet_id()
# XXX: Great, now we've got the cells, let's do something.
# file:///home/jml/Desktop/gdata-2.0.17/pydocs/gdata.spreadsheets.data.html#CellEntry
cells = client.get_cells(key, sheet_id)
for e in cells.entry:
    print e.content.text

# XXX: Want to add a bunch of rows to the expense spreadsheet

# XXX: For now, hard code the december sheet, but in future, decide on a policy
# for managing them automatically.
# https://developers.google.com/google-apps/documents-list/

# XXX: Do this
# To store the token object in a secured datastore or keystore, the
Пример #6
0
credentials = credential_storage.get()

if credentials == None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage)

client = gdata.spreadsheets.client.SpreadsheetsClient()
token = gdata.gauth.OAuth2Token(client_id=flow.client_id,
                                client_secret=flow.client_secret,
                                scope=flow.scope,
                                user_agent="chisubmit",
                                access_token=credentials.access_token,
                                refresh_token=credentials.refresh_token)
token.authorize(client)

# Open spreadsheet
worksheets = client.get_worksheets(SPREADSHEET_KEY)

# Get first worksheet
worksheet_id = worksheets.entry[0].get_worksheet_id()

feed = client.get_list_feed(SPREADSHEET_KEY, worksheet_id)

for row in feed.entry:
    print "============================================"
    group = row.to_dict()

    if course.teams.has_key(group[GROUPNAME]):
        print "Skipping '%s'. Already exists." % group[GROUPNAME]
        continue

    print "Adding group '%s'" % group[GROUPNAME]
Пример #7
0
# -*- coding: utf-8 -*-

from oauth2client.client import SignedJwtAssertionCredentials
import gdata.spreadsheets.client

# 認証に必要な情報
client_email = "*****@*****.**" # 手順2で発行されたメールアドレス
with open("bigquery-python-ca3e147753fe.p12") as f: private_key = f.read() # 手順2で発行された秘密鍵

# 認証情報の作成
scope = ["https://spreadsheets.google.com/feeds"]
credentials = SignedJwtAssertionCredentials(client_email, private_key,
    scope=scope)

# スプレッドシート用クライアントの準備
client = gdata.spreadsheets.client.SpreadsheetsClient()

# OAuth2.0での認証設定
auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
auth_token.authorize(client)

# ---- これでライブラリを利用してスプレッドシートにアクセスできる ---- #

# ワークシートの取得
sheets = client.get_worksheets("1F5opPDJ5CaAZyGwZrlfUlc4dso3sQ6KBdKIIK6970SA") # スプレッドシートIDを指定
for sheet in sheets.entry:
    print sheet.get_worksheet_id()

cell = client.get_cell("1F5opPDJ5CaAZyGwZrlfUlc4dso3sQ6KBdKIIK6970SA", "ontqp3p", 7, 2)
print cell.__dict__
print cell.title
Пример #8
0
token.authorize(client)

print
print "Test #1: list all spreadsheets"
sheets = client.get_spreadsheets()
for entry in sheets.entry:
    sid = re.sub(r'.*\/', '', entry.get_id())
    print "title:", entry.title.text
    print "  url:", entry.get_id()
    print "   id:", sid
    if entry.title.text == 'platform-gps-prjs-201408':
        prjs_sheet_id = sid

print
print "Test#2: list all worksheets in 'platform-gps-prjs-201408 (%s)'" % prjs_sheet_id
worksheets = client.get_worksheets(prjs_sheet_id)
for entry in worksheets.entry:
    wid = re.sub(r'.*\/', '', entry.get_id())
    print "title:", entry.title.text
    print "  url:", entry.get_id()
    print "   id:", wid
    if entry.title.text == 'platform-gps-prjs-201407':
        prjs_worksheet_id = wid

print
print "Test#3: list some columns of raw #1 in 'platform-gps-prjs-201408'"
row = 1
for column in range(1, 10):
    cell = client.get_cell(prjs_sheet_id, prjs_worksheet_id, 1, column)
    print "  [%d, %d] %s" % (row, column, cell.content.text)