Skip to content

Commit 8bfdf17

Browse files
committed
refactor
1 parent 1443421 commit 8bfdf17

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

sources/bing_webmaster/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66
"""
77

88
import time
9-
from typing import Iterable, Iterator, List, Sequence
9+
from typing import Dict, Iterator, List, Sequence
1010

1111
import dlt
1212
from dlt.common import logger
13-
from dlt.common.typing import DictStrAny, DictStrStr
13+
from dlt.common.typing import DictStrAny
1414
from dlt.sources import DltResource
1515

1616
from .helpers import get_stats_with_retry, parse_response
1717

1818

1919
@dlt.source(name="bing_webmaster")
2020
def source(
21-
site_urls: List[str] = None, site_url_pages: Iterable[DictStrStr] = None
21+
site_urls: List[str] = dlt.config.value,
22+
site_url_pages: List[Dict[str,str]] = dlt.config.value,
2223
) -> Sequence[DltResource]:
2324
"""
2425
A dlt source for the Bing Webmaster api.
2526
It groups resources for the APIs which return organic search traffic statistics
2627
Args:
2728
site_urls: List[str]: A list of site_urls, e.g, ["dlthub.com", "dlthub.de"]. Use this if you need the weekly traffic per site_url and page
28-
site_url_pages: Iterable[DictStrStr]: A list of pairs of site_url and page. Use this if you need the weekly traffic per site_url, page, and query
29+
site_url_pages: Iterable[Dict[str, str]]: A list of pairs of site_url and page. Use this if you need the weekly traffic per site_url, page, and query
2930
Returns:
3031
Sequence[DltResource]: A sequence of resources that can be selected from including page_stats and page_query_stats.
3132
"""
@@ -42,7 +43,7 @@ def source(
4243
table_name="bing_page_stats",
4344
)
4445
def page_stats(
45-
site_urls: List[str], api_key: str = dlt.secrets.value
46+
site_urls: List[str], api_key: str = dlt.secrets.value # here # investigate
4647
) -> Iterator[Iterator[DictStrAny]]:
4748
"""
4849
Yields detailed traffic statistics for top pages belonging to a site_url
@@ -70,7 +71,7 @@ def page_stats(
7071
table_name="bing_page_query_stats",
7172
)
7273
def page_query_stats(
73-
site_url_pages: Iterable[DictStrStr],
74+
site_url_pages: List[Dict[str, str]],
7475
api_key: str = dlt.secrets.value,
7576
) -> Iterator[Iterator[DictStrAny]]:
7677
"""
@@ -80,7 +81,7 @@ def page_query_stats(
8081
https://learn.microsoft.com/en-us/dotnet/api/microsoft.bing.webmaster.api.interfaces.iwebmasterapi.getpagequerystats
8182
8283
Args:
83-
site_url_page (Iterable[DictStrStr]): Iterable of site_url and pages to retrieve statistics for. Can be result of a SQL query, a parsed sitemap, etc.
84+
site_url_page (List[Dict[str,str]]): Iterable of site_url and pages to retrieve statistics for. Can be result of a SQL query, a parsed sitemap, etc.
8485
Yields:
8586
Iterator[Dict[str, Any]]: An iterator over list of organic traffic statistics.
8687
"""

sources/chess/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
@dlt.source(name="chess")
1616
def source(
17-
players: List[str], start_month: str = None, end_month: str = None
17+
players: List[str] = dlt.config.value,
18+
start_month: str = None,
19+
end_month: str = None
1820
) -> Sequence[DltResource]:
1921
"""
2022
A dlt source for the chess.com api. It groups several resources (in this case chess.com API endpoints) containing

sources/kafka/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
standalone=True,
2828
)
2929
def kafka_consumer(
30-
topics: Union[str, List[str]],
30+
topics: List[str] = dlt.config.value,
3131
credentials: Union[KafkaCredentials, Consumer] = dlt.secrets.value,
3232
msg_processor: Optional[
3333
Callable[[Message], Dict[str, Any]]
@@ -60,9 +60,6 @@ def kafka_consumer(
6060
Yields:
6161
Iterable[TDataItem]: Kafka messages.
6262
"""
63-
if not isinstance(topics, list):
64-
topics = [topics]
65-
6663
if isinstance(credentials, Consumer):
6764
consumer = credentials
6865
elif isinstance(credentials, KafkaCredentials):

sources/kafka_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def custom_msg_processor(msg: confluent_kafka.Message) -> Dict[str, Any]:
4747
"data": msg.value().decode("utf-8"),
4848
}
4949

50-
data = kafka_consumer("books", msg_processor=custom_msg_processor)
50+
data = kafka_consumer(["books"], msg_processor=custom_msg_processor)
5151

5252
info = pipeline.run(data)
5353
print(info)
@@ -63,7 +63,7 @@ def load_starting_from_date() -> None:
6363
)
6464

6565
from_date = datetime(2023, 12, 15)
66-
data = kafka_consumer("books", start_from=from_date)
66+
data = kafka_consumer(["books"], start_from=from_date)
6767

6868
info = pipeline.run(data)
6969
print(info)

0 commit comments

Comments
 (0)