Skip to content

Commit ece2b4c

Browse files
committed
fix: fixed lints and type issues
1 parent a50c6a1 commit ece2b4c

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

aw_client/cli.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
11
#!/usr/bin/env python3
22
import json
3-
import argparse
43
import logging
54
import textwrap
6-
from typing import Optional, List
7-
from datetime import timedelta, datetime, timezone
5+
from datetime import datetime, timedelta, timezone
6+
from typing import List, Optional
87

98
import click
10-
from tabulate import tabulate
11-
129
from aw_core import Event
10+
from tabulate import tabulate
1311

1412
import aw_client
13+
1514
from . import queries
1615
from .classes import default_classes
1716

18-
1917
now = datetime.now(timezone.utc)
2018
td1day = timedelta(days=1)
2119
td1yr = timedelta(days=365)
2220

2321
logger = logging.getLogger(__name__)
2422

2523

26-
def _valid_date(s):
27-
# https://stackoverflow.com/questions/25470844/specify-format-for-input-arguments-argparse-python
28-
try:
29-
return datetime.strptime(s, "%Y-%m-%d")
30-
except ValueError:
31-
msg = f"Not a valid date: '{s}'."
32-
raise argparse.ArgumentTypeError(msg)
33-
34-
3524
class _Context:
3625
client: aw_client.ActivityWatchClient
3726

aw_client/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def _post(
127127
)
128128

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

@@ -323,7 +325,7 @@ def query(
323325
assert _dt_is_tzaware(start)
324326
assert _dt_is_tzaware(stop)
325327
except AssertionError:
326-
raise ValueError("start/stop needs to have a timezone set")
328+
raise ValueError("start/stop needs to have a timezone set") from None
327329

328330
data = {
329331
"timeperiods": [

examples/redact_sensitive.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010

1111
import re
1212
import sys
13-
from typing import List, Set, Pattern, Union, cast
1413
from copy import deepcopy
14+
from typing import (
15+
List,
16+
Pattern,
17+
Set,
18+
Union,
19+
cast,
20+
)
1521

16-
from aw_core import Event
1722
from aw_client import ActivityWatchClient
23+
from aw_core import Event
1824

1925
aw: ActivityWatchClient
2026

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

105111

106112
def _check_event(e: Event, pattern: Union[str, Pattern]) -> bool:
107-
for k, v in e.data.items():
113+
for v in e.data.values():
108114
if isinstance(v, str):
109115
if isinstance(pattern, str):
110116
if pattern in v.lower():

examples/working_hours_gspread.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import socket
2222
import sys
2323
from datetime import datetime, time, timedelta
24+
from typing import Union
2425

2526
import gspread
27+
from gspread.utils import ValueInputOption
2628

2729
import working_hours
2830

@@ -102,7 +104,7 @@ def update_sheet(sheet_key: str, regex: str):
102104
working_hours.generous_approx(r["events"], break_time).total_seconds()
103105
/ 3600
104106
)
105-
row = [str(date), duration]
107+
row: list[Union[str, float]] = [str(date), duration]
106108

107109
# If the date is the same as the last entry, update it
108110
if last_date and date == last_date:
@@ -111,7 +113,7 @@ def update_sheet(sheet_key: str, regex: str):
111113
# If the date is later than the last entry, append it
112114
elif not last_date or date > last_date:
113115
print(f"Appending {row}")
114-
worksheet.append_row(row, value_input_option="USER_ENTERED")
116+
worksheet.append_row(row, value_input_option=ValueInputOption.user_entered)
115117
else:
116118
print(f"Skipping {row}")
117119

0 commit comments

Comments
 (0)