9
9
from notion_client .helpers import iterate_paginated_api
10
10
11
11
12
- # logging.basicConfig(level=logging.DEBUG)
13
-
14
- # if is_logging():
15
- # logger = logging.getLogger("dlt")
16
-
17
- # class HideSinglePagingNonsense(logging.Filter):
18
- # def filter(self, record):
19
- # msg = record.getMessage()
20
- # if (
21
- # "Extracted data of type list from path _data with length 1" in msg
22
- # or re.match(
23
- # r"Paginator JSONLinkPaginator at [a-fA-F0-9]+: next_url_path: _meta\.links\.next\.href does not have more pages",
24
- # msg,
25
- # )
26
- # ):
27
- # return False
28
- # return True
29
-
30
- # logger.addFilter(HideSinglePagingNonsense())
31
-
32
-
33
- # def anyurl_encoder(obj: Any) -> JsonSerializable:
34
- # if isinstance(obj, AnyUrl):
35
- # return obj.unicode_string()
36
- # raise TypeError(f"Object of type {type(obj)} is not JSON serializable")
37
-
38
-
39
- # json.set_custom_encoder(anyurl_encoder)
40
-
41
-
42
- # def pydantic_model_dump(model: BaseModel, **kwargs):
43
- # """
44
- # Dumps a Pydantic model to a dictionary, using the model's field names as keys and NOT observing the field aliases,
45
- # which is important for DLT to correctly map the data to the destination.
46
- # """
47
- # return model.model_dump(by_alias=True, **kwargs)
48
-
49
-
50
12
class Table (StrEnum ):
51
13
PERSONS = "persons"
52
14
BOTS = "bots"
@@ -56,72 +18,12 @@ def use_id(entity: Dict, **kwargs) -> Dict:
56
18
return filter_dict (entity , ** kwargs ) | {"_dlt_id" : __get_id (entity )}
57
19
58
20
59
- # @dlt.resource(
60
- # selected=True,
61
- # parallelized=True,
62
- # primary_key="id",
63
- # )
64
- # def persons(rest_client: RESTClient) -> Iterable[TDataItem]:
65
- # for persons_raw in rest_client.paginate(
66
- # V2_PERSONS, params={"limit": V2_MAX_PAGE_LIMIT}, hooks=hooks
67
- # ):
68
- # yield persons_adapter.validate_python(persons_raw)
69
-
70
-
71
- # async def person_employments(
72
- # person: Person,
73
- # rest_client: RESTClient,
74
- # ):
75
- # href = jmespath.search("links.employments.href", person.field_meta)
76
- # if not href:
77
- # return
78
- # for employments_raw in rest_client.paginate(
79
- # href, params={"limit": V2_MAX_PAGE_LIMIT}, hooks=hooks
80
- # ):
81
- # employments = employments_adapter.validate_python(employments_raw)
82
- # for employment in employments:
83
- # yield dlt.mark.with_hints(
84
- # item=use_id(employment, exclude=["field_meta", "org_units"]),
85
- # hints=dlt.mark.make_hints(
86
- # table_name=Table.EMPLOYMENTS.value,
87
- # ),
88
- # # needs to be a variant due to https://github.com/dlt-hub/dlt/pull/2109
89
- # create_table_variant=True,
90
- # )
91
-
92
-
93
21
def __get_id (obj ):
94
22
if isinstance (obj , dict ):
95
23
return obj .get ("id" )
96
24
return getattr (obj , "id" , None )
97
25
98
26
99
- # @dlt.transformer(
100
- # max_table_nesting=1,
101
- # parallelized=True,
102
- # table_name=Table.PERSONS.value,
103
- # )
104
- # async def person_details(persons: List[Person], rest_client: RESTClient):
105
- # yield [
106
- # use_id(person, exclude=["field_meta", "custom_attributes", "employments"])
107
- # for person in persons
108
- # ]
109
- # for person in persons:
110
- # yield person_employments(person, rest_client)
111
- # yield dlt.mark.with_hints(
112
- # item={"person_id": person.id}
113
- # | {cas.root.id: cas.root.value for cas in person.custom_attributes},
114
- # hints=dlt.mark.make_hints(
115
- # table_name=Table.CUSTOM_ATTRIBUTES.value,
116
- # primary_key="person_id",
117
- # merge_key="person_id",
118
- # write_disposition="merge",
119
- # ),
120
- # # needs to be a variant due to https://github.com/dlt-hub/dlt/pull/2109
121
- # create_table_variant=True,
122
- # )
123
-
124
-
125
27
@dlt .resource (
126
28
selected = True ,
127
29
parallelized = True ,
0 commit comments