Skip to content

Commit

Permalink
fix: fixed lints and type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Sep 29, 2024
1 parent a50c6a1 commit ea27f7d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
19 changes: 4 additions & 15 deletions aw_client/cli.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
#!/usr/bin/env python3
import json
import argparse
import logging
import textwrap
from typing import Optional, List
from datetime import timedelta, datetime, timezone
from datetime import datetime, timedelta, timezone
from typing import List, Optional

import click
from tabulate import tabulate

from aw_core import Event
from tabulate import tabulate

import aw_client

from . import queries
from .classes import default_classes


now = datetime.now(timezone.utc)
td1day = timedelta(days=1)
td1yr = timedelta(days=365)

logger = logging.getLogger(__name__)


def _valid_date(s):
# https://stackoverflow.com/questions/25470844/specify-format-for-input-arguments-argparse-python
try:
return datetime.strptime(s, "%Y-%m-%d")
except ValueError:
msg = f"Not a valid date: '{s}'."
raise argparse.ArgumentTypeError(msg)


class _Context:
client: aw_client.ActivityWatchClient

Expand Down
6 changes: 4 additions & 2 deletions aw_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def _post(
)

@always_raise_for_request_errors
def _delete(self, endpoint: str, data: Any = dict()) -> req.Response:
def _delete(self, endpoint: str, data: Any = None) -> req.Response:
if data is None:
data = {}
headers = {"Content-type": "application/json"}
return req.delete(self._url(endpoint), data=json.dumps(data), headers=headers)

Expand Down Expand Up @@ -323,7 +325,7 @@ def query(
assert _dt_is_tzaware(start)
assert _dt_is_tzaware(stop)
except AssertionError:
raise ValueError("start/stop needs to have a timezone set")
raise ValueError("start/stop needs to have a timezone set") from None

data = {
"timeperiods": [
Expand Down
12 changes: 9 additions & 3 deletions examples/redact_sensitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@

import re
import sys
from typing import List, Set, Pattern, Union, cast
from copy import deepcopy
from typing import (
List,
Pattern,
Set,
Union,
cast,
)

from aw_core import Event
from aw_client import ActivityWatchClient
from aw_core import Event

aw: ActivityWatchClient

Expand Down Expand Up @@ -104,7 +110,7 @@ def _redact_bucket(bucket_id: str, pattern: Union[str, Pattern]):


def _check_event(e: Event, pattern: Union[str, Pattern]) -> bool:
for k, v in e.data.items():
for v in e.data.values():
if isinstance(v, str):
if isinstance(pattern, str):
if pattern in v.lower():
Expand Down
5 changes: 3 additions & 2 deletions examples/working_hours_gspread.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from datetime import datetime, time, timedelta

import gspread
from gspread.utils import ValueInputOption

import working_hours

Expand Down Expand Up @@ -102,7 +103,7 @@ def update_sheet(sheet_key: str, regex: str):
working_hours.generous_approx(r["events"], break_time).total_seconds()
/ 3600
)
row = [str(date), duration]
row: list[str | float] = [str(date), duration]

# If the date is the same as the last entry, update it
if last_date and date == last_date:
Expand All @@ -111,7 +112,7 @@ def update_sheet(sheet_key: str, regex: str):
# If the date is later than the last entry, append it
elif not last_date or date > last_date:
print(f"Appending {row}")
worksheet.append_row(row, value_input_option="USER_ENTERED")
worksheet.append_row(row, value_input_option=ValueInputOption.user_entered)
else:
print(f"Skipping {row}")

Expand Down

0 comments on commit ea27f7d

Please sign in to comment.