Reformat code using black

This commit is contained in:
2020-08-16 00:00:08 +02:00
parent 000e3d7f8a
commit 607bb18fb3
15 changed files with 317 additions and 217 deletions

View File

@ -5,25 +5,26 @@ import gspread
from oauth2client.service_account import ServiceAccountCredentials
from toggl.TogglPy import Toggl
#this test demonstrates how to link up the toggl API into a google sheet
#in order to do this, you'll need to first setup your google account developer environment
#to do this, you can follow the instructions here: http://tinaja.computer/2017/10/27/gspread.html
#additional information about the spread API here: https://github.com/burnash/gspread
# this test demonstrates how to link up the toggl API into a google sheet
# in order to do this, you'll need to first setup your google account developer environment
# to do this, you can follow the instructions here: http://tinaja.computer/2017/10/27/gspread.html
# additional information about the spread API here: https://github.com/burnash/gspread
# as such, to run this test you'll need to define the following env variables
# TOGGL_API_KEY : your toggl api key
# WORKSPACE_ID: a workspace id that you'd like to dump data for
# KEYFILE: the full path to your google suite keyfile (keep this secret/safe!)
# SHEET_URL: the url of the google sheet you are writing to
#as such, to run this test you'll need to define the following env variables
#TOGGL_API_KEY : your toggl api key
#WORKSPACE_ID: a workspace id that you'd like to dump data for
#KEYFILE: the full path to your google suite keyfile (keep this secret/safe!)
#SHEET_URL: the url of the google sheet you are writing to
class Toggl2GSuiteTest(unittest.TestCase):
def setUp(self):
self.api_key = os.environ['TOGGL_API_KEY']
self.api_key = os.environ["TOGGL_API_KEY"]
self.toggl = Toggl()
self.toggl.setAPIKey(self.api_key)
# see https://stackoverflow.com/questions/19153462/get-excel-style-column-names-from-column-number
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@staticmethod
def excel_style(row, col):
@ -32,35 +33,48 @@ class Toggl2GSuiteTest(unittest.TestCase):
while col:
col, rem = divmod(col - 1, 26)
result[:0] = Toggl2GSuiteTest.LETTERS[rem]
return ''.join(result) + str(row)
return "".join(result) + str(row)
def test_toggl2gsuite(self):
# have to do this year by year
data = {
'workspace_id': os.environ['WORKSPACE_ID'],
"workspace_id": os.environ["WORKSPACE_ID"],
}
y = self.toggl.getDetailedReport(data)
credentials = ServiceAccountCredentials.from_json_keyfile_name(
os.environ['KEYFILE'],
['https://spreadsheets.google.com/feeds'])
os.environ["KEYFILE"], ["https://spreadsheets.google.com/feeds"]
)
client = gspread.authorize(credentials)
sheet = client.open_by_url(os.environ['SHEET_URL'])
sheet = client.open_by_url(os.environ["SHEET_URL"])
worksheet = sheet.get_worksheet(0)
wrote_header = False
columns_to_write = ['user', 'updated', 'start', 'end', 'client', 'project', 'description', 'is_billable',
'billable']
columns_to_write = [
"user",
"updated",
"start",
"end",
"client",
"project",
"description",
"is_billable",
"billable",
]
cell_row = 0
for row_idx, rec in enumerate(y['data']):
for row_idx, rec in enumerate(y["data"]):
if wrote_header == False:
for col_idx, header in enumerate(columns_to_write):
worksheet.update_acell(Toggl2GSuiteTest.excel_style(row_idx + 1, col_idx + 1), header)
worksheet.update_acell(
Toggl2GSuiteTest.excel_style(row_idx + 1, col_idx + 1), header
)
wrote_header = True
for col_idx, header in enumerate(columns_to_write):
worksheet.update_acell(Toggl2GSuiteTest.excel_style(row_idx + 2, col_idx + 1), rec[header])
worksheet.update_acell(
Toggl2GSuiteTest.excel_style(row_idx + 2, col_idx + 1), rec[header]
)
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()