Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Linting #40

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions tap_indeedsponsoredjobs/auth.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""IndeedSponsoredJobs Authentication."""

import logging
from typing import Callable, Generator
from typing import Callable
from urllib.parse import urlparse

import backoff
import requests
from requests import Request, Session
from requests import Session
from singer_sdk.authenticators import OAuthAuthenticator
from singer_sdk.exceptions import FatalAPIError, RetriableAPIError
from singer_sdk.helpers._util import utc_now
Expand Down Expand Up @@ -71,15 +70,23 @@ def create_multiemployerauth_for_stream(cls, stream):
return cls(
stream=stream,
auth_endpoint="https://apis.indeed.com/oauth/v2/tokens",
oauth_scopes="employer.advertising.subaccount.read employer.advertising.account.read employer.advertising.campaign.read employer.advertising.campaign_report.read employer_access",
oauth_scopes=(
"employer.advertising.subaccount.read employer.advertising.account.read"
" employer.advertising.campaign.read employer.advertising.campaign_repo"
"rt.read employer_access",
),
)

@classmethod
def create_singleemployerauth_for_stream(cls, stream, employerid):
return cls(
stream=stream,
auth_endpoint="https://apis.indeed.com/oauth/v2/tokens",
oauth_scopes="employer.advertising.subaccount.read employer.advertising.account.read employer.advertising.campaign.read employer.advertising.campaign_report.read",
oauth_scopes=(
"employer.advertising.subaccount.read employer.advertising.account.read"
" employer.advertising.campaign.read employer.advertising.campaign_repo"
"rt.read"
),
employerid=employerid,
)

Expand Down Expand Up @@ -172,10 +179,9 @@ def backoff_handler(self, details) -> None:
details: backoff invocation details
https://github.com/litl/backoff#event-handlers
"""
logging.error(
self.logger.error(
"Backing off {wait:0.1f} seconds after {tries} tries "
"calling function {target} with args {args} and kwargs "
"{kwargs}".format(**details)
"calling function {target}".format(**details)
)

def validate_response(self, response: requests.Response) -> None:
Expand Down
15 changes: 6 additions & 9 deletions tap_indeedsponsoredjobs/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"""REST client handling, including IndeedSponsoredJobsStream base class."""

from __future__ import annotations
import copy

import json
import logging
from collections import OrderedDict
from pathlib import Path
from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Union
from typing import Any, Callable, Dict, Generator, Iterable, Optional
from urllib.parse import urlparse

import backoff
Expand Down Expand Up @@ -41,7 +38,8 @@ def get_next_url(self, response):
)
)
raise Exception(
"Pagination not implemented yet, but we require pagination here. With perpage being so high this is surprising!"
"Pagination not implemented yet, but we require pagination here. With "
"perpage being so high this is surprising!"
)
return retval
except StopIteration:
Expand Down Expand Up @@ -297,7 +295,7 @@ def validate_response(self, response: requests.Response) -> None:
def is_json(self, myjson):
try:
json.loads(myjson)
except ValueError as e:
except ValueError:
return False
return True

Expand Down Expand Up @@ -344,15 +342,15 @@ def get_records(self, context: dict | None) -> Iterable[dict[str, Any]]:
yield transformed_record
except ScopeNotWorkingForEmployerID as e:
self.logger.warning(e)

def backoff_max_tries(self) -> int:
"""The number of attempts before giving up when retrying requests.

Returns:
Number of max retries.
"""
return 20

def backoff_wait_generator(self) -> Generator[float, None, None]:
"""The wait generator used by the backoff decorator on request failure.

Expand Down Expand Up @@ -396,4 +394,3 @@ def request_decorator(self, func: Callable) -> Callable:
on_backoff=self.backoff_handler,
)(func)
return decorator

Loading