Spaces:
Sleeping
Sleeping
Jhon Alexander Alvarez Casas
commited on
Commit
·
bfe7c08
1
Parent(s):
80aff54
upload files
Browse files- app/core/{s3_config.py → s3.py} +0 -0
- app/core/template.py +3 -2
- main.py +6 -7
- template/b2b-order-creation +3 -2
app/core/{s3_config.py → s3.py}
RENAMED
|
File without changes
|
app/core/template.py
CHANGED
|
@@ -2,5 +2,6 @@ class Template:
|
|
| 2 |
@staticmethod
|
| 3 |
def read(file_name):
|
| 4 |
with open(f"template/{file_name}", 'r') as file:
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
| 2 |
@staticmethod
|
| 3 |
def read(file_name):
|
| 4 |
with open(f"template/{file_name}", 'r') as file:
|
| 5 |
+
template = file.read()
|
| 6 |
+
template = template.replace("{{", "{{{{").replace("}}", "}}}}")
|
| 7 |
+
return template
|
main.py
CHANGED
|
@@ -5,6 +5,7 @@ from ttp import ttp
|
|
| 5 |
|
| 6 |
from app.core.s3_config import s3
|
| 7 |
from app.core.supabase import supabase_client
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
@@ -23,13 +24,11 @@ def data(bucket: str, project: str, local_date: str, env_file: UploadFile = File
|
|
| 23 |
|
| 24 |
|
| 25 |
@app.get("/data")
|
| 26 |
-
async def data(project: str, local_date: str):
|
| 27 |
local_folder = f"data/{project}/{local_date}"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
values = {"project": project, "local_date": local_date}
|
| 32 |
-
template = template.format_map(values)
|
| 33 |
parser = ttp(data=f"{local_folder}/data.txt", template=template)
|
| 34 |
parser.parse()
|
| 35 |
result = parser.result()[0][0]
|
|
@@ -41,4 +40,4 @@ async def data(project: str, local_date: str):
|
|
| 41 |
pass
|
| 42 |
except Exception as e:
|
| 43 |
print(f"error desde {i}: {e}")
|
| 44 |
-
return
|
|
|
|
| 5 |
|
| 6 |
from app.core.s3_config import s3
|
| 7 |
from app.core.supabase import supabase_client
|
| 8 |
+
from app.core.template import Template
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
@app.get("/data")
|
| 27 |
+
async def data(project: str, local_date: str, process: str):
|
| 28 |
local_folder = f"data/{project}/{local_date}"
|
| 29 |
+
template = Template.read(process)
|
| 30 |
+
values = {"project": project, "local_date": local_date, "process": process}
|
| 31 |
+
template = template.format_map(values)
|
|
|
|
|
|
|
| 32 |
parser = ttp(data=f"{local_folder}/data.txt", template=template)
|
| 33 |
parser.parse()
|
| 34 |
result = parser.result()[0][0]
|
|
|
|
| 40 |
pass
|
| 41 |
except Exception as e:
|
| 42 |
print(f"error desde {i}: {e}")
|
| 43 |
+
return result
|
template/b2b-order-creation
CHANGED
|
@@ -4,12 +4,13 @@ from datetime import datetime
|
|
| 4 |
def attrs(data):
|
| 5 |
project = "{project}"
|
| 6 |
local_date = "{local_date}"
|
| 7 |
-
|
|
|
|
| 8 |
data["key"] = hashlib.sha256(key.encode()).hexdigest()
|
| 9 |
data["updated_at"] = datetime.now().isoformat()
|
| 10 |
-
data["process"] = "order-creation"
|
| 11 |
data["project"] = project
|
| 12 |
data["local_date"] = local_date
|
|
|
|
| 13 |
return data
|
| 14 |
</macro>
|
| 15 |
<group macro="attrs">
|
|
|
|
| 4 |
def attrs(data):
|
| 5 |
project = "{project}"
|
| 6 |
local_date = "{local_date}"
|
| 7 |
+
process = "{process}"
|
| 8 |
+
key = project + "-" + local_date + "-" + process + "-" + data["ip"] + "-" + data["date"] + "-" + data["body"]
|
| 9 |
data["key"] = hashlib.sha256(key.encode()).hexdigest()
|
| 10 |
data["updated_at"] = datetime.now().isoformat()
|
|
|
|
| 11 |
data["project"] = project
|
| 12 |
data["local_date"] = local_date
|
| 13 |
+
data["process"] = process
|
| 14 |
return data
|
| 15 |
</macro>
|
| 16 |
<group macro="attrs">
|