def insert_row(data): entry = gdata.spreadsheets.data.ListEntry() for k, v in data.iteritems(): entry.set_value(k, v) client.add_list_entry(entry, os.environ['SS_KEY'], 'od6')
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)
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)
def powerCycle2GSheet(queue): print "powerCycle2GSheet started" config = ConfigParser.RawConfigParser() config.read('PBMonitor.config') clientId = config.get('Google','clientId') clientSecret = config.get('Google','clientSecret') userAgent = config.get('Google','userAgent') refreshToken = config.get('Google','refreshToken') gSheetKey = config.get('Google', 'gSheetKey') clientScope='https://spreadsheets.google.com/feeds/' token = gdata.gauth.OAuth2Token(client_id=clientId, client_secret=clientSecret, scope=clientScope, user_agent=userAgent, refresh_token=refreshToken) client = gdata.spreadsheets.client.SpreadsheetsClient() token.authorize(client) entry = client.get_list_feed(gSheetKey, 'od6').entry[0] powerCycle = PowerCycle() dict = '' while dict != 'PBMonShutDown': dict = queue.get() if dict != 'PBMonShutDown': print "Read powerCycle from queue: ", dict for t in dict: entry.set_value(t.lower(),str(dict[t])) retry = True while retry: try: client.add_list_entry(entry,gSheetKey,'od6') print "Data sent to GSheet" retry = False except: retry = True time.delay(60) print "Transmission to GSheet failed, retrying in 60 seconds"
def upload_historical(client, since_days_ago): counts = calculate_burnup(since_days_ago=since_days_ago) for date in sorted(counts.keys()): stats = calculate_stats(on_date=date) # Must specify spreadsheet headers as lowercase, silly Google API entry = gdata.spreadsheets.data.ListEntry() data = {'date': date.isoformat(), 'total': "%d" % counts[date]['total'], 'closed': "%d" % counts[date]['closed'], 'bugs': "%d" % stats['bugs'], 'bugsclosedinlastweek': "%d" % stats['bugs_closed_in_last_week'], 'bugsopenedinlastweek': "%d" % stats['bugs_opened_in_last_week'], 'p1': "%d" % stats['p1'], 'p2': "%d" % stats['p2'], 'p3': "%d" % stats['p3'], 'security': "%d" % stats['security'], 'ota': "%d" % stats['ota'], 'quicksync': "%d" % stats['quick_sync']} entry.from_dict(data) client.add_list_entry(entry, BURNUP_CHART_SPREADSHEET_KEY, DEFAULT_WORKSHEET_ID) print("Uploaded data for %s" % date.isoformat())
def upload_historical(client, since_days_ago): counts = calculate_burnup(since_days_ago=since_days_ago) for date in sorted(counts.keys()): stats = calculate_stats(on_date=date) # Must specify spreadsheet headers as lowercase, silly Google API entry = gdata.spreadsheets.data.ListEntry() data = { 'date': date.isoformat(), 'total': "%d" % counts[date]['total'], 'closed': "%d" % counts[date]['closed'], 'bugs': "%d" % stats['bugs'], 'bugsclosedinlastweek': "%d" % stats['bugs_closed_in_last_week'], 'bugsopenedinlastweek': "%d" % stats['bugs_opened_in_last_week'], 'p1': "%d" % stats['p1'], 'p2': "%d" % stats['p2'], 'p3': "%d" % stats['p3'], 'security': "%d" % stats['security'], 'ota': "%d" % stats['ota'], 'quicksync': "%d" % stats['quick_sync'] } entry.from_dict(data) client.add_list_entry(entry, BURNUP_CHART_SPREADSHEET_KEY, DEFAULT_WORKSHEET_ID) print("Uploaded data for %s" % date.isoformat())
def writeRow(rowDict, client, sheetKey, sheetID='od6'): fixedRow = convertRow(rowDict) listEntry = ListEntry() listEntry.from_dict(fixedRow) client.add_list_entry(listEntry, sheetKey, sheetID)