-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
305 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import httpx | ||
|
||
|
||
def extract(id: str, url: str, token: str, **kwargs) -> bytes: | ||
headers = {"Authorization": f"Bearer {token}"} | ||
response = httpx.post(url, headers=headers) | ||
response.raise_for_status() | ||
return response.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,3 +136,8 @@ sources: | |
schema: brevo | ||
tables: | ||
- name: contacts | ||
|
||
- name: fredo | ||
schema: fredo | ||
tables: | ||
- name: structures |
140 changes: 140 additions & 0 deletions
140
pipeline/dbt/models/staging/sources/fredo/_fredo__models.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: stg_fredo__structures | ||
columns: | ||
- name: id | ||
tests: | ||
- unique | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: adresse | ||
tests: | ||
- not_null: | ||
config: | ||
severity: warn | ||
- dbt_utils.not_empty_string | ||
- name: code_postal | ||
tests: | ||
- not_null: | ||
config: | ||
severity: warn | ||
- dbt_utils.not_empty_string | ||
- name: commune | ||
tests: | ||
- not_null: | ||
config: | ||
severity: warn | ||
- dbt_utils.not_empty_string | ||
- name: frais | ||
tests: | ||
- dbt_utils.not_empty_string | ||
- name: horaires_ouverture | ||
tests: | ||
- dbt_utils.not_empty_string | ||
- name: lien_source | ||
tests: | ||
- dbt_utils.not_empty_string | ||
- name: nom | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
- name: presentation_resume | ||
tests: | ||
- dbt_utils.not_empty_string | ||
- name: siret | ||
tests: | ||
- dbt_utils.not_empty_string | ||
- name: telephone | ||
tests: | ||
- dbt_utils.not_empty_string | ||
- name: latitude | ||
- name: longitude | ||
- name: categories | ||
- name: publics | ||
- name: quartiers | ||
- name: services | ||
- name: type_structure | ||
|
||
- name: stg_fredo__categories | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
- relationships: | ||
to: ref('stg_fredo__structures') | ||
field: id | ||
- name: value | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: stg_fredo__frais | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
- relationships: | ||
to: ref('stg_fredo__structures') | ||
field: id | ||
- name: value | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
- accepted_values: | ||
values: ['gratuit', 'payant', 'sur-rendez-vous', 'sans-rendez-vous'] | ||
config: | ||
severity: warn | ||
|
||
- name: stg_fredo__publics | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
- relationships: | ||
to: ref('stg_fredo__structures') | ||
field: id | ||
- name: value | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: stg_fredo__quartiers | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
- relationships: | ||
to: ref('stg_fredo__structures') | ||
field: id | ||
- name: value | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: stg_fredo__services | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
- relationships: | ||
to: ref('stg_fredo__structures') | ||
field: id | ||
- name: value | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: stg_fredo__types | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null | ||
- relationships: | ||
to: ref('stg_fredo__structures') | ||
field: id | ||
- name: value | ||
tests: | ||
- not_null | ||
- dbt_utils.not_empty_string |
13 changes: 13 additions & 0 deletions
13
pipeline/dbt/models/staging/sources/fredo/stg_fredo__categories.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
LOWER(TRIM(JSONB_ARRAY_ELEMENTS_TEXT(data -> 'categories'))) AS "value" | ||
FROM source | ||
WHERE data ->> 'categories' IS NOT NULL | ||
) | ||
|
||
SELECT * FROM final |
14 changes: 14 additions & 0 deletions
14
pipeline/dbt/models/staging/sources/fredo/stg_fredo__frais.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
REPLACE(LOWER(TRIM(frais)), 'rendez vous', 'rendez-vous') AS "value" | ||
FROM | ||
source, | ||
LATERAL UNNEST(STRING_TO_ARRAY(data->>'frais', '/')) AS frais | ||
) | ||
|
||
SELECT * FROM final |
13 changes: 13 additions & 0 deletions
13
pipeline/dbt/models/staging/sources/fredo/stg_fredo__publics.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
LOWER(TRIM(JSONB_ARRAY_ELEMENTS_TEXT(data -> 'publics'))) AS "value" | ||
FROM source | ||
WHERE data ->> 'publics' IS NOT NULL | ||
) | ||
|
||
SELECT * FROM final |
13 changes: 13 additions & 0 deletions
13
pipeline/dbt/models/staging/sources/fredo/stg_fredo__quartiers.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
JSONB_ARRAY_ELEMENTS_TEXT(data -> 'quartiers') AS "value" | ||
FROM source | ||
WHERE data ->> 'quartiers' IS NOT NULL | ||
) | ||
|
||
SELECT * FROM final |
13 changes: 13 additions & 0 deletions
13
pipeline/dbt/models/staging/sources/fredo/stg_fredo__services.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
LOWER(TRIM(JSONB_ARRAY_ELEMENTS_TEXT(data -> 'services'))) AS "value" | ||
FROM source | ||
WHERE data ->> 'services' IS NOT NULL | ||
) | ||
|
||
SELECT * FROM final |
48 changes: 48 additions & 0 deletions
48
pipeline/dbt/models/staging/sources/fredo/stg_fredo__structures.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
NULLIF(TRIM(data ->> 'adresse'), '') AS "adresse", | ||
NULLIF(TRIM(data ->> 'code_postal'), '') AS "code_postal", | ||
NULLIF(TRIM(data ->> 'commune'), '') AS "commune", | ||
NULLIF(TRIM(data ->> 'frais'), '') AS "frais", | ||
NULLIF(TRIM(data ->> 'horaires_ouverture'), '') AS "horaires_ouverture", | ||
NULLIF(TRIM(data ->> 'lien_source'), '') AS "lien_source", | ||
NULLIF(TRIM(data ->> 'nom'), '') AS "nom", | ||
NULLIF(TRIM(data ->> 'presentation_resume'), '') AS "presentation_resume", | ||
NULLIF(TRIM(data ->> 'siret'), '') AS "siret", | ||
NULLIF(TRIM(data ->> 'telephone'), '') AS "telephone", | ||
CAST(NULLIF(TRIM(data ->> 'latitude'), '') AS FLOAT) AS "latitude", | ||
CAST(NULLIF(TRIM(data ->> 'longitude'), '') AS FLOAT) AS "longitude", | ||
CASE | ||
WHEN data ->> 'categories' IS NOT NULL | ||
THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'categories')) AS TEXT []) | ||
ELSE CAST(NULL AS TEXT []) | ||
END AS "categories", | ||
CASE | ||
WHEN data ->> 'publics' IS NOT NULL | ||
THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'publics')) AS TEXT []) | ||
ELSE CAST(NULL AS TEXT []) | ||
END AS "publics", | ||
CASE | ||
WHEN data ->> 'quartiers' IS NOT NULL | ||
THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'quartiers')) AS TEXT []) | ||
ELSE CAST(NULL AS TEXT []) | ||
END AS "quartiers", | ||
CASE | ||
WHEN data ->> 'services' IS NOT NULL | ||
THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'services')) AS TEXT []) | ||
ELSE CAST(NULL AS TEXT []) | ||
END AS "services", | ||
CASE | ||
WHEN data ->> 'type_structure' IS NOT NULL | ||
THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'type_structure')) AS TEXT []) | ||
ELSE CAST(NULL AS TEXT []) | ||
END AS "type_structure" | ||
FROM source | ||
) | ||
|
||
SELECT * FROM final |
13 changes: 13 additions & 0 deletions
13
pipeline/dbt/models/staging/sources/fredo/stg_fredo__types.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('fredo', 'structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
data ->> 'id' AS "id", | ||
LOWER(TRIM(JSONB_ARRAY_ELEMENTS_TEXT(data -> 'type_structure'))) AS "value" | ||
FROM source | ||
WHERE data ->> 'type_structure' IS NOT NULL | ||
) | ||
|
||
SELECT * FROM final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters