Skip to content

Commit

Permalink
Init logic for mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Oct 31, 2023
1 parent 84a4ebe commit 21dd3ae
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ requires-python = '>=3.10, <4'
dependencies = [
'fastapi',
'Jinja2',
'rdflib',
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uvicorn
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ annotated-types==0.6.0
anyio==3.7.1
fastapi==0.104.1
idna==3.4
isodate==0.6.1
Jinja2==3.1.2
MarkupSafe==2.1.3
pydantic==2.4.2
pydantic_core==2.10.1
pyparsing==3.1.1
rdflib==7.0.0
six==1.16.0
sniffio==1.3.0
starlette==0.27.0
typing_extensions==4.8.0
5 changes: 5 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

export $(grep -v '^#' .env | xargs)

uvicorn fip2dmp_importer:app --reload
40 changes: 40 additions & 0 deletions src/smp_importer/logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class _MappingExecutor:

def __init__(self):
self.result = []
self.variables = {}

def reset(self):
self.result = []
self.variables = {}

def result_add(self, action: str, **kwargs):
self.result.append({
'type': action,
**kwargs,
})

def result_debug(self, message: str):
self.result_add(action='debug', message=message)

def result_add_item(self, path: str, var_name: str):
self.result_add(action='addItem', path=path.split('.'), var=var_name)

def result_set_reply(self, path: str, value: str):
self.result_add(action='setReply', path=path.split('.'), value=value)

def result_set_integration_reply(self, path: str, value: str, item_id):
self.result_add(action='setIntegrationReply', path=path.split('.'), value=value, itemId=item_id)

def get_result_dict(self):
return {
'actions': self.result,
}


def prepare_import_mapping(contents: str, content_type: str) -> dict:
executor = _MappingExecutor()

# TODO: process contents in custom functions, etc.

return executor.get_result_dict()

0 comments on commit 21dd3ae

Please sign in to comment.