Skip to content

Commit

Permalink
chore: added type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancheley committed Jan 11, 2022
1 parent 4a0395f commit dd0db66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gitclean:

# run mypy on the files
mypy:
mypy src/toggl_to_sqlite/*.py --no-strict-optional
mypy src/toggl_to_sqlite/*.py --no-strict-optional --ignore-missing-imports


# generates the README.md file --help section
Expand Down
11 changes: 6 additions & 5 deletions src/toggl_to_sqlite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import math

import requests
import sqlite_utils


def get_start_datetime(api_token, since: datetime = None):
def get_start_datetime(api_token: str, since: datetime.datetime = None) -> datetime.date:
toggl = requests.get("https://api.track.toggl.com/api/v8/me", auth=(api_token, "api_token"))
if toggl.status_code == 200:
data = toggl.json()
Expand All @@ -18,7 +19,7 @@ def get_start_datetime(api_token, since: datetime = None):
return datetime.date.today()


def get_workspaces(api_token):
def get_workspaces(api_token: str) -> list:
workspaces = []
response = requests.get("https://api.track.toggl.com/api/v8/workspaces", auth=(api_token, "api_token"))
if response.status_code == 200:
Expand All @@ -28,7 +29,7 @@ def get_workspaces(api_token):
return workspaces


def get_projects(api_token):
def get_projects(api_token: str) -> list:
projects = []
workspaces = get_workspaces(api_token)
if len(workspaces) > 0:
Expand All @@ -44,7 +45,7 @@ def get_projects(api_token):
return projects


def get_time_entries(api_token, days, since: datetime = None):
def get_time_entries(api_token: str, days: int, since: datetime.datetime = None) -> list:
start_date = get_start_datetime(api_token, since)
today = datetime.date.today()
data = []
Expand All @@ -67,7 +68,7 @@ def get_time_entries(api_token, days, since: datetime = None):
return data


def save_items(items, table, db):
def save_items(items: list, table: str, db: sqlite_utils.Database) -> None:
for item in items:
data = item
db[table].insert_all(data, pk="id", alter=True, replace=True)

0 comments on commit dd0db66

Please sign in to comment.