-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(pipeline): add imilo as a new data source #365
base: main
Are you sure you want to change the base?
Changes from all commits
70f51b6
3d614fb
7dae2a1
1890a2c
acf2bee
5c0c1ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import json | ||
|
||
import requests | ||
|
||
|
||
class ImiloClient: | ||
def __init__(self, base_url: str, secret: str) -> None: | ||
self.base_url = base_url.rstrip("/") | ||
self.session = requests.Session() | ||
self.session.headers.update({"Content-Type": "application/json"}) | ||
self.secret = secret | ||
|
||
# The token lasts 1h | ||
def _get_token(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quelle est la durée de vie de ce token ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 heure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merci ! est-ce que tu peux ajouter un petit commentaire pour l'indiquer ? |
||
response = self.session.post( | ||
url=f"{self.base_url}/get_token", | ||
data=json.dumps( | ||
{ | ||
"client_secret": self.secret, | ||
} | ||
), | ||
) | ||
response.raise_for_status() | ||
self.session.headers.update( | ||
{"Authorization": f"Bearer {response.json()['access_token']}"} | ||
) | ||
|
||
def _get_endpoint( | ||
self, | ||
url_path: str, | ||
) -> list: | ||
next_url = f"{self.base_url}{url_path}" | ||
response = self.session.get(next_url) | ||
if response.status_code == 401: | ||
self._get_token() | ||
response = self.session.get(next_url) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def list_offres(self) -> list: | ||
return self._get_endpoint("/get_offres") | ||
|
||
def list_structures(self) -> list: | ||
return self._get_endpoint("/get_structures") | ||
|
||
def list_structures_offres(self) -> list: | ||
return self._get_endpoint("/get_structures_offres") | ||
|
||
|
||
def extract(id: str, url: str, token: str, **kwargs) -> bytes: | ||
client = ImiloClient(base_url=url, secret=token) | ||
data = getattr(client, f"list_{id}")() | ||
return json.dumps(data).encode() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: int_imilo__adresses | ||
data_tests: | ||
- check_adresse: | ||
config: | ||
severity: warn | ||
columns: | ||
- name: id | ||
data_tests: | ||
- unique | ||
- not_null | ||
|
||
- name: int_imilo__services | ||
data_tests: | ||
- check_service: | ||
config: | ||
severity: warn | ||
columns: | ||
- name: id | ||
data_tests: | ||
- unique | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
- name: structure_id | ||
data_tests: | ||
- not_null | ||
- relationships: | ||
to: ref('int_imilo__structures') | ||
field: id | ||
|
||
- name: int_imilo__structures | ||
data_tests: | ||
- check_structure: | ||
config: | ||
severity: warn | ||
columns: | ||
- name: id | ||
data_tests: | ||
- unique | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
- name: adresse_id | ||
data_tests: | ||
- not_null | ||
- relationships: | ||
to: ref('int_imilo__adresses') | ||
field: id |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
WITH structures AS ( | ||
SELECT * FROM {{ ref('stg_imilo__structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
id AS "id", | ||
commune AS "commune", | ||
code_postal AS "code_postal", | ||
code_insee AS "code_insee", | ||
adresse AS "adresse", | ||
complement_adresse AS "complement_adresse", | ||
CAST(NULL AS FLOAT) AS "longitude", | ||
CAST(NULL AS FLOAT) AS "latitude", | ||
_di_source_id AS "source" | ||
FROM structures | ||
) | ||
|
||
SELECT * FROM final |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
WITH services AS ( | ||
SELECT * FROM {{ ref('stg_imilo__offres') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
services._di_source_id AS "source", | ||
CONCAT( | ||
structures_offres.id_offre, | ||
'_', | ||
structures_offres.id_structure | ||
) AS "id", | ||
CAST(structures_offres."id_structure" AS TEXT) AS "structure_id", | ||
NULL AS "courriel", | ||
CAST(NULL AS BOOLEAN) AS "cumulable", | ||
CAST(NULL AS BOOLEAN) AS "contact_public", | ||
NULL AS "contact_nom_prenom", | ||
CAST(services.date_maj AS DATE) AS "date_maj", | ||
CAST(services.date_creation AS DATE) AS "date_creation", | ||
NULL AS "formulaire_en_ligne", | ||
NULL AS "frais_autres", | ||
CAST(NULL AS TEXT []) AS "justificatifs", | ||
NULL AS "lien_source", | ||
CAST(NULL AS TEXT []) AS "modes_accueil", | ||
CAST(NULL AS TEXT []) AS "modes_orientation_accompagnateur", | ||
NULL AS "modes_orientation_accompagnateur_autres", | ||
ARRAY[services.modes_orientation_beneficiaire] AS "modes_orientation_beneficiaire", | ||
NULL AS "modes_orientation_beneficiaire_autres", | ||
services.nom AS "nom", | ||
NULL AS "page_web", | ||
NULL AS "presentation_detail", | ||
services.presentation_resume AS "presentation_resume", | ||
NULL AS "prise_rdv", | ||
ARRAY[services.profils] AS "profils", | ||
NULL AS "profils_precisions", | ||
CAST(NULL AS TEXT []) AS "pre_requis", | ||
NULL AS "recurrence", | ||
ARRAY[services.thematiques] AS "thematiques", | ||
CAST(NULL AS TEXT []) AS "types", | ||
NULL AS "telephone", | ||
CAST(NULL AS TEXT []) AS "frais", | ||
NULL AS "zone_diffusion_type", | ||
NULL AS "zone_diffusion_code", | ||
NULL AS "zone_diffusion_nom", | ||
CAST(NULL AS DATE) AS "date_suspension" | ||
FROM services | ||
LEFT JOIN {{ ref('stg_imilo__structures_offres') }} AS structures_offres | ||
ON services.id = structures_offres.id_offre | ||
) | ||
|
||
SELECT * FROM final |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
WITH structures AS ( | ||
SELECT * FROM {{ ref('stg_imilo__structures') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
_di_source_id AS "source", | ||
id AS "id", | ||
siret AS "siret", | ||
NULL AS "rna", | ||
courriel AS "courriel", | ||
CAST(NULL AS BOOLEAN) AS "antenne", | ||
horaires_ouverture AS "horaires_ouverture", | ||
site_web AS "site_web", | ||
NULL AS "lien_source", | ||
NULL AS "accessibilite", | ||
telephone AS "telephone", | ||
typologie AS "typologie", | ||
nom AS "nom", | ||
ARRAY[labels_nationaux] AS "labels_nationaux", | ||
CAST(NULL AS TEXT []) AS "labels_autres", | ||
presentation_resume AS "presentation_resume", | ||
presentation_detail AS "presentation_detail", | ||
id AS "adresse_id", | ||
CAST(NULL AS TEXT []) AS "thematiques", | ||
CAST(date_maj AS DATE) AS "date_maj" | ||
FROM structures | ||
|
||
) | ||
|
||
SELECT * FROM final |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.