-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
154 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"type": "service_account", | ||
"project_id": "angelic-bee-411621", | ||
"private_key_id": "dd685fb9db8522658c4c0f07982a9439d5319115", | ||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCVsA1O+bllO6m7\nVWwYTVglXu0hIK27ihxhpsvgIV4eYeVkZj+YaDxeLDTR3mFCLCKDJ8Qjv3S2s1jz\nD/JvHT7nqWUF87VxXX4fgU10uMDIeeSM7KjhIeNPoIvFJm4kYN5PmufGtUK5+tSw\nSys8uDhjpb6cG+CVUeNwUnEFhJbAEgyProjZsW/snO+Y1o3OdN1G0CutPzmTpn+b\nLZ0/Mf/QXFcWZlfU0L9OwnJ8xiIO2aHFWS5S4vO98hzvSxsDh1vhMx4fVwyuld5P\n3NEJV8p/XmraCJFbrGVUZiaYhGv8VHhTYvlPZq3mhR+udBAoIDTzgHU+QjFL4ixa\njzmc3N3VAgMBAAECggEACZSPfX8BLSgA6IMCnJmSqy2kqqqfQ/IGd/+Ha+xmzDYC\nywa6SkRdnL9ikA4WFnihqthINuuBilH3PvNF1nO+O3B9jUB4W+2abWTGstJCUHJw\nvM5GzsXu+QEzAObBROXIRLsK245tW17g7vmYplW6EjKg/PfRy2zGzEESh8JhLaDA\n/pSUOFktaJp3GPAdvLx4Wa0kPRb4Y7+/ARiWH5KQGduEGiFl3gK1wHZhdKO6rPlE\njiwGlKKsHMowSZYltiebLv9e9+W/ACbToLWctXXASNzfYeke7Chp+JbbG5sjcHri\nPIxC2t30B1h9AlQh4O919LNKDxDoQjowCuZHicb9QQKBgQDQdGQWKQ61CJ7oZ3dZ\nBwgBJy3PDoFPnuE71Rcvzrs79CI4Dm1N02gXMvtkCC6Q4X2krGuJagWwK7OeIKDW\nqj5Y1gk/CICk0R8xVmR0Cvt1chlIGZtngs9kNyd78mSR6fdmWKQa9kH+gmeDXZ/0\nHv/T0eCGD82K9ogDsMGkDPjKoQKBgQC31EZ2atn6pve6wXyVIKRNa82T7odh/kiH\nnu4KjqneeacYzAIxrp0g4YOe6uwjfWBKJ4KT/mx93AOIjj/eluiPaV0UYnGGikGu\nvgKTbhUvJNGlzR718+FMnGqJa04FH29tgGgOV6ETSGAdOiV7wrxLBx8ru/3cbipD\nNP+DMBlatQKBgQCQvrEc3ieTN0g4clfiHsrFGjJp21WZNuaJCF9QWAmVCOGV8Rae\n+tQFf+YlwLSs75ax+PO2+EK44K+ZdmiYhqBCSWUkOsAxMfCp7qZUGaggFjlN4lIR\nnzhpCw9Etrx0wXSDwbs56ZNLqbs88Y73EWts5wgzrtd3zdYGUf8z7bn34QKBgDik\nBmX8PFe31ILNlTZZzWYxfjFDgKFX+T8YYB4OoRZ0g2DnkxF9zNpRwf1YQxQYUG/o\nxpoU/Za2ELyln9ZUxylQ/KYIQxSCSwStdRu6Anr5LEOa9RwxXcz+MPFQh8SaT/n8\nY5Nvuqi3Vy4KOXxtnxi7BAa0sN6XbxwwGz5vtpA1AoGATooJ3hY9ECgaq6yuK/YF\nl4R7hiTV6Yr7qx1DMbqBv2SpXy3pL4Onh1y2+rpvgH1B5LDLZ25euHRG3GHSuScE\nGcVN7PJ/7p1S/jUZ/Fx9ypKaG++yfU3KvRxW7trbE/8AS9CP5Uph/8UYQ016ilX4\nV/uSgS5MbZCWouIashyFIsc=\n-----END PRIVATE KEY-----\n", | ||
"client_email": "[email protected]", | ||
"client_id": "107655704552755133565", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/abr-432%40angelic-bee-411621.iam.gserviceaccount.com", | ||
"universe_domain": "googleapis.com" | ||
} |
116 changes: 116 additions & 0 deletions
116
hardware-testing/hardware_testing/google_sheets_tool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import gspread | ||
import socket | ||
import httplib2 | ||
from oauth2client.service_account import ServiceAccountCredentials | ||
from typing import (Any, Dict, Iterator, List, | ||
Optional, Sequence, Set, Tuple, Union) | ||
import pprint | ||
|
||
"""This module requires a creditials.json file before getting started. | ||
The following link provides a step by step tutorial on how to get startd. | ||
https://towardsdatascience.com/accessing-google-spreadsheet-data-using-python-90a5bc214fd2""" | ||
|
||
class google_sheet: | ||
""" | ||
This module was designed for the testing team to automate tests by | ||
ultizing google sheets API to record data. The following attributes that this | ||
class needs is the file_name and the tab_number define. | ||
""" | ||
def __init__(self, creditals, file_name, tab_number): | ||
self.scope = ['https://spreadsheets.google.com/feeds', | ||
'https://www.googleapis.com/auth/drive'] | ||
self.creditals = \ | ||
ServiceAccountCredentials.from_json_keyfile_name(creditals, self.scope) | ||
self.gc = gspread.authorize(self.creditals) | ||
self.file_name = file_name | ||
self.tab_number = tab_number | ||
self.spread_sheet = self.open_google_sheet() | ||
self.worksheet = self.open_worksheet(self.tab_number) | ||
self.row_index = 1 | ||
|
||
def open_google_sheet(self): | ||
"""Open Google Spread Sheet""" | ||
sheet = self.gc.open(self.file_name) | ||
return sheet | ||
|
||
def open_worksheet(self, tab_number: int )-> classmethod: | ||
"""Open individual worksheet within a googlesheet""" | ||
return self.spread_sheet.get_worksheet(tab_number) | ||
|
||
def create_worksheet(self, tab_name: int): | ||
"""Create a worksheet with a title for a tab. This method need | ||
to have an existing spreadsheet for it to work.""" | ||
try: | ||
self.spread_sheet.add_worksheet(tab_name, rows="1000", cols="26") | ||
except gspread.exceptions.APIError: | ||
print('Work Sheet already exists') | ||
|
||
def write_header(self, header: List): | ||
"""Write Header to first row, this method as determines if the first row | ||
has a header that identical to the header the user is writing too.""" | ||
header_list = self.worksheet.row_values(1) | ||
print(header_list) | ||
if header_list != header: | ||
self.worksheet.insert_row(header, self.row_index) | ||
|
||
def write_to_row(self, data: List): | ||
"""Write data into a row in a List[] format, this method skips the first | ||
row of the worksheet due to headers. """ | ||
try: | ||
self.row_index += 1 | ||
self.worksheet.insert_row(data, index= self.row_index) | ||
except socket.gaierror: | ||
pass | ||
except httplib2.ServerNotFoundError: | ||
print('UNABLE TO CONNECT TO SERVER!!, CHECK CONNECTION') | ||
except Exception as error: | ||
print(error.traceback) | ||
|
||
def delete_row(row_index: int): | ||
"""Delete Row from google sheet""" | ||
self.worksheet.delete_row(row_index) | ||
|
||
def update_cell(self, row: int, column: int, single_data: any): | ||
"""Update an individual cell according to a row and column. Note that | ||
this function only updates one individual cell""" | ||
self.worksheet.update_cell(row, column, data) | ||
|
||
def update_cells(self, cells, data): | ||
cell_list = self.worksheet.range(cells) | ||
self.worksheet.update_cells(data) | ||
|
||
def get_all_data(self)-> Dict[str, any]: | ||
"""Get all the Data recorded from worksheet.""" | ||
return self.worksheet.get_all_records() | ||
|
||
def get_column(self, column_number: int)-> int: | ||
return self.worksheet.col_values(column_number) | ||
|
||
def get_index_row(self): | ||
"""Check for the next available row to write too.""" | ||
row_index = len(self.get_column(1)) | ||
print("Row Index: ", row_index) | ||
return row_index | ||
|
||
def update_row_index(self): | ||
"""Update self.row_index instance variable""" | ||
self.row_index = self.get_index_row() | ||
|
||
|
||
def get_all_sheets(self): | ||
"""List all tabs in the spreadsheets""" | ||
worksheets = self.spread_sheet.worksheets() | ||
return worksheets | ||
|
||
def get_sheet_by_name(self, title: str): | ||
#worksheet = sh.worksheet("January") | ||
try: | ||
worksheet = self.spread_sheet.worksheet(title) | ||
return worksheet | ||
except gspread.exceptions.WorksheetNotFound: | ||
raise 'Worksheet does not exist!!, create a \ | ||
worksheet first using the create_worksheet() function.' | ||
|
||
def token_check(): | ||
if self.creditals.access_token_expired: | ||
self.gc.login() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters