Skip to content

Commit 77b32bf

Browse files
chore(deps): pre-commit autoupdate (#77)
* chore(deps): pre-commit autoupdate updates: - [github.com/python-jsonschema/check-jsonschema: 0.23.2 → 0.26.3](python-jsonschema/check-jsonschema@0.23.2...0.26.3) - https://github.com/charliermarsh/ruff-pre-commithttps://github.com/astral-sh/ruff-pre-commit - [github.com/astral-sh/ruff-pre-commit: v0.0.277 → v0.0.287](astral-sh/ruff-pre-commit@v0.0.277...v0.0.287) - [github.com/psf/black: 23.3.0 → 23.7.0](psf/black@23.3.0...23.7.0) - [github.com/pre-commit/mirrors-mypy: v1.4.1 → v1.5.1](pre-commit/mirrors-mypy@v1.4.1...v1.5.1) * Make Ruff ⚡ happy --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
1 parent ffbdb28 commit 77b32bf

File tree

3 files changed

+81
-120
lines changed

3 files changed

+81
-120
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ repos:
1616
- id: trailing-whitespace
1717

1818
- repo: https://github.com/python-jsonschema/check-jsonschema
19-
rev: 0.23.2
19+
rev: 0.26.3
2020
hooks:
2121
- id: check-dependabot
2222
- id: check-github-workflows
2323

24-
- repo: https://github.com/charliermarsh/ruff-pre-commit
25-
rev: v0.0.277
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: v0.0.287
2626
hooks:
2727
- id: ruff
2828
args: ["--fix"]
2929

3030
- repo: https://github.com/psf/black
31-
rev: 23.3.0
31+
rev: 23.7.0
3232
hooks:
3333
- id: black
3434

3535
- repo: https://github.com/pre-commit/mirrors-mypy
36-
rev: v1.4.1
36+
rev: v1.5.1
3737
hooks:
3838
- id: mypy
3939
pass_filenames: true

tap_linkedin_ads/client.py

Lines changed: 49 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import typing as t
67
from datetime import datetime, timezone
78
from pathlib import Path
@@ -55,8 +56,8 @@ def http_headers(self) -> dict:
5556
def get_next_page_token(
5657
self,
5758
response: requests.Response,
58-
previous_token: t.Any | None,
59-
) -> t.Any | None:
59+
previous_token: t.Any | None, # noqa: ANN401
60+
) -> t.Any | None: # noqa: ANN401
6061
"""Return a token for identifying next page or None if no more pages."""
6162
# If pagination is required, return a token which can be used to get the
6263
# next page. If this is the final page, return "None" to end the
@@ -67,20 +68,19 @@ def get_next_page_token(
6768

6869
elements = resp_json.get("elements")
6970

70-
if elements is not None:
71-
if len(elements) == 0 or len(elements) == previous_token + 1:
72-
return None
73-
else:
71+
if elements is None:
7472
page = resp_json
75-
if len(page) == 0 or len(page) == previous_token + 1:
73+
if len(page) in [0, previous_token + 1]:
7674
return None
7775

76+
elif len(elements) in [0, previous_token + 1]:
77+
return None
7878
return previous_token + 1
7979

8080
def get_url_params(
8181
self,
8282
context: dict | None, # noqa: ARG002
83-
next_page_token: t.Any | None,
83+
next_page_token: t.Any | None, # noqa: ANN401
8484
) -> dict[str, t.Any]:
8585
"""Return a dictionary of values to be used in URL parameterization.
8686
@@ -100,7 +100,7 @@ def get_url_params(
100100

101101
return params
102102

103-
def parse_response( # noqa: PLR0912
103+
def parse_response(
104104
self,
105105
response: requests.Response,
106106
) -> t.Iterable[dict]:
@@ -117,72 +117,58 @@ def parse_response( # noqa: PLR0912
117117
results = resp_json["elements"]
118118
try:
119119
columns = results[0]
120-
except: # noqa: E722
120+
except Exception: # noqa: BLE001
121121
columns = results
122-
pass
123-
try:
124-
created_time = (
125-
columns.get("changeAuditStamps").get("created").get("time")
126-
)
127-
last_modified_time = (
128-
columns.get("changeAuditStamps").get("lastModified").get("time")
129-
)
130-
columns["created_time"] = datetime.fromtimestamp(
131-
int(created_time) / 1000,
132-
tz=UTC,
133-
).isoformat()
134-
columns["last_modified_time"] = datetime.fromtimestamp(
135-
int(last_modified_time) / 1000,
136-
tz=UTC,
137-
).isoformat()
138-
except: # noqa: E722, S110
139-
pass
122+
with contextlib.suppress(Exception):
123+
self._add_datetime_columns(columns)
124+
140125
else:
141126
results = resp_json
142127
try:
143128
columns = results
144-
created_time = (
145-
columns.get("changeAuditStamps").get("created").get("time")
146-
)
147-
last_modified_time = (
148-
columns.get("changeAuditStamps").get("lastModified").get("time")
149-
)
150-
columns["created_time"] = datetime.fromtimestamp(
151-
int(created_time) / 1000,
152-
tz=UTC,
153-
).isoformat()
154-
columns["last_modified_time"] = datetime.fromtimestamp(
155-
int(last_modified_time) / 1000,
156-
tz=UTC,
157-
).isoformat()
158-
except: # noqa: E722
129+
self._add_datetime_columns(columns)
130+
except Exception: # noqa: BLE001
159131
columns = results
160-
pass
161-
162-
try:
163-
account_column = columns.get("account")
164-
account_id = int(account_column.split(":")[3])
165-
columns["account_id"] = account_id
166-
except: # noqa: E722, S110
167-
pass
168-
try:
169-
campaign_column = columns.get("campaignGroup")
170-
campaign = int(campaign_column.split(":")[3])
171-
columns["campaign_group_id"] = campaign
172-
except: # noqa: E722, S110
173-
pass
174-
try:
132+
with contextlib.suppress(Exception):
133+
self._to_id_column(columns, "account", "account_id")
134+
135+
with contextlib.suppress(Exception):
136+
self._to_id_column(
137+
columns,
138+
"campaignGroup",
139+
"campaign_group_id",
140+
)
141+
with contextlib.suppress(Exception):
175142
schedule_column = columns.get("runSchedule").get("start")
176143
columns["run_schedule_start"] = datetime.fromtimestamp( # noqa: DTZ006
177144
int(schedule_column) / 1000,
178145
).isoformat()
179-
except: # noqa: E722, S110
180-
pass
181-
182-
results = (
146+
yield from (
183147
resp_json["elements"]
184148
if resp_json.get("elements") is not None
185149
else [columns]
186150
)
187151

188-
yield from results
152+
def _to_id_column(
153+
self,
154+
columns, # noqa: ANN001
155+
arg1, # noqa: ANN001
156+
arg2, # noqa: ANN001
157+
) -> None:
158+
account_column = columns.get(arg1)
159+
account_id = int(account_column.split(":")[3])
160+
columns[arg2] = account_id
161+
162+
def _add_datetime_columns(self, columns): # noqa: ANN202, ANN001
163+
created_time = columns.get("changeAuditStamps").get("created").get("time")
164+
last_modified_time = (
165+
columns.get("changeAuditStamps").get("lastModified").get("time")
166+
)
167+
columns["created_time"] = datetime.fromtimestamp(
168+
int(created_time) / 1000,
169+
tz=UTC,
170+
).isoformat()
171+
columns["last_modified_time"] = datetime.fromtimestamp(
172+
int(last_modified_time) / 1000,
173+
tz=UTC,
174+
).isoformat()

0 commit comments

Comments
 (0)