Skip to content

Commit 490f6d9

Browse files
authored
Merge pull request #4 from Libertech-FR/dataWeaver
Data weaver
2 parents 8604aee + 4f1fd09 commit 490f6d9

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import base64
33
import logging
4-
import os
4+
import os, glob
55
from dotenv import load_dotenv
66
import hashlib
77
import sys
@@ -101,12 +101,17 @@ async def main():
101101
logger.info("Starting Taiga ind/pictures crawler...")
102102
print(f"Imports: {args.imports}")
103103
await a_moins_b(url, 0, -1, headers)
104-
collection_tasks = [col.get('function')(url, col, headers) for col in collections]
104+
# suppression des fichiers cache
105+
listjson=glob.glob('./cache/*.json')
106+
for file in listjson:
107+
os.remove(file)
105108

106-
if args.imports == 'ind' or args.imports == 'all':
107-
collection_tasks = [col.get('function')(url, col, headers) for col in collections if col.get('method') != 'ExportPhotos']
108-
if args.imports == 'pictures' or args.imports == 'all':
109-
collection_tasks = [col.get('function')(url, col, headers) for col in collections if col.get('method') == 'ExportPhotos']
109+
if args.imports == 'ind':
110+
collection_tasks = [col.get('function')(url, col, headers) for col in collections if col.get('method') != 'ExportPhotos']
111+
elif args.imports == 'pictures':
112+
collection_tasks = [col.get('function')(url, col, headers) for col in collections if col.get('method') == 'ExportPhotos']
113+
else:
114+
collection_tasks = [col.get('function')(url, col, headers) for col in collections]
110115

111116
await asyncio.gather(*collection_tasks)
112117
print("Taiga crawler ended successful !!!")

src/import_ind.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import aiohttp
66
import dotenv
77
import yaml
8+
import re
89

910
dotenv.load_dotenv()
1011
sesame_api_baseurl = os.getenv('SESAME_API_BASEURL')
@@ -27,7 +28,7 @@ async def read_response(response):
2728
jsonMessage = json.loads(message)
2829
print(jsonMessage)
2930

30-
async def send_request(session, url, json):
31+
async def send_request(session, url,exclusions, json):
3132
headers = {
3233
"Authorization": f"Bearer {sesame_api_token}",
3334
"Content-Type": "application/json; charset=utf-8",
@@ -36,7 +37,14 @@ async def send_request(session, url, json):
3637
"filters[inetOrgPerson.employeeNumber]": f"{json.get('inetOrgPerson', {}).get('employeeNumber')}",
3738
"filters[inetOrgPerson.employeeType]": "TAIGA",
3839
}
39-
40+
for regex in exclusions:
41+
for r in regex:
42+
value=json.get('inetOrgPerson').get(r)
43+
if value:
44+
result=re.search(regex[r],value)
45+
if result != None:
46+
print(f"EXCLUDED {json.get('inetOrgPerson', {}).get('employeeNumber')} {json.get('inetOrgPerson', {}).get('cn')}")
47+
return
4048
try:
4149

4250
async with session.post(url, json=json, headers=headers, params=params) as response:
@@ -75,7 +83,8 @@ async def process_data(data, config, file, session):
7583
result = await get_data(data, config)
7684
with open(f'./data/{file}', 'w', encoding='utf-8') as fichier:
7785
json.dump(result, fichier, ensure_ascii=False, indent=4)
78-
tasks = [send_request(session, f'{sesame_api_baseurl}/management/identities/upsert', entry) for entry in result]
86+
exclude=config.get('exclude',[])
87+
tasks = [send_request(session, f'{sesame_api_baseurl}/management/identities/upsert',config.get('exclude',[]),entry) for entry in result]
7988
await gather_with_concurrency(sesame_import_parallels_files, tasks)
8089
print(f"Processed {file}")
8190

0 commit comments

Comments
 (0)