Skip to content

Commit 8497df0

Browse files
committed
Implements dockerfile and authentification api
1 parent bfd3c3a commit 8497df0

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ cache/
22
logs/
33
.env
44
src/__pycache__/*
5-
data/*
65
.idea/

Dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ WORKDIR /data
88

99
ARG UID=10001
1010
RUN adduser \
11-
--disabled-password \
12-
--gecos "" \
13-
--home "/nonexistent" \
14-
--shell "/sbin/nologin" \
15-
--no-create-home \
16-
--uid "${UID}" \
17-
appuser
11+
--disabled-password \
12+
--gecos "" \
13+
--home "/nonexistent" \
14+
--shell "/sbin/nologin" \
15+
--no-create-home \
16+
--uid "${UID}" \
17+
appuser
1818

1919
RUN --mount=type=cache,target=/root/.cache/pip \
20-
--mount=type=bind,source=requirements.txt,target=requirements.txt \
21-
python -m pip install -r requirements.txt
20+
--mount=type=bind,source=requirements.txt,target=requirements.txt \
21+
python -m pip install -r requirements.txt
2222

2323
USER appuser
2424

2525
COPY . .
2626

27-
CMD py main.py
27+
CMD python main.py

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
include .env
22
STC_API_HOST?=taiga.archi.fr
33
STC_API_FORWARD_PORT?=1337
4+
IMG_NAME = "ghcr.io/libertech-fr/sesame-taiga_crawler"
5+
BASE_NAME = "sesame"
6+
APP_NAME = "sesame-taiga_crawler"
7+
PLATFORM = "linux/amd64"
48

59
.DEFAULT_GOAL := help
610
help:
711
@printf "\033[33mUsage:\033[0m\n make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m\n"
812
@grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) \
913
| sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}'
1014

15+
build: ## Construit l'image docker
16+
@printf "\033[33mDOCKER:\033[0m Build docker image ...\n"
17+
@docker build -t sesame-taiga_crawler .
18+
@printf "\033[33mDOCKER:\033[0m SUCCESSFUL !!!\n"
19+
20+
run-crawler-docker: ## Lance le crawler Sesame - Taiga avec python !
21+
@docker run --rm -it \
22+
--add-host host.docker.internal:host-gateway \
23+
--network dev \
24+
--platform $(PLATFORM) \
25+
--name $(APP_NAME) \
26+
-v $(CURDIR):/data \
27+
sesame-taiga_crawler
28+
1129
run-crawler: ## Lance le crawler Sesame - Taiga avec python !
1230
@python3 main.py
1331

data/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666

6767

6868
async def main():
69-
logger.info("Starting Taiga crawler...")
70-
await a_moins_b(url, 0, -1, headers)
71-
collection_tasks = [col.get('function')(url, col, headers) for col in collections]
72-
await asyncio.gather(*collection_tasks)
73-
print("Taiga crawler ended successful !!!")
69+
# logger.info("Starting Taiga crawler...")
70+
# await a_moins_b(url, 0, -1, headers)
71+
# collection_tasks = [col.get('function')(url, col, headers) for col in collections]
72+
# await asyncio.gather(*collection_tasks)
73+
# print("Taiga crawler ended successful !!!")
7474

7575
print("Starting import_ind...")
7676
start_time = datetime.now()
-139 Bytes
Binary file not shown.
-1.06 KB
Binary file not shown.
-1.32 KB
Binary file not shown.

src/import_ind.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ async def sem_task(task):
109109
return await asyncio.gather(*[sem_task(task) for task in tasks])
110110

111111
async def send_request(session, url, json):
112+
token = os.getenv('SESAME_API_TOKEN')
113+
headers = {
114+
"Authorization": f"Bearer {token}",
115+
"Content-Type": "application/json; charset=utf-8",
116+
}
117+
112118
try:
113-
async with session.post(url, json=json) as response:
119+
print(f"json: {json}")
120+
async with session.post(url, json=json, headers=headers) as response:
114121
response.raise_for_status() # Raises error for 4xx/5xx responses
115122
print(f"Request to {url} successful: {response.status}")
116123
except aiohttp.ClientError as e:
@@ -125,7 +132,7 @@ async def get_data(data, config):
125132
result.append(treated)
126133
return result
127134

128-
135+
129136

130137
async def process_data(data, config, file, session):
131138
print(f"Processing {file}")
@@ -147,4 +154,4 @@ async def import_ind():
147154
# for file in cache_files:
148155
# await process_data(datas[file], configs[file], file, session)
149156
tasks = [process_data(datas[file], configs[file], file, session) for file in cache_files]
150-
await gather_with_concurrency(10, tasks)
157+
await gather_with_concurrency(10, tasks)

0 commit comments

Comments
 (0)