Skip to content
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

V1.1 mongodb #1

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7d2b2ce
changed title
vg-leanix Dec 14, 2020
ea740de
new title
vg-leanix Dec 14, 2020
e4b09fe
updated gitignore
vg-leanix Dec 14, 2020
00ea1b5
cleansing
vg-leanix Dec 19, 2020
8e8548f
monngodb backend + ws
vg-leanix Dec 19, 2020
cbc1381
docker cheatsheet
vg-leanix Dec 19, 2020
bc7fdf1
more stable build
vg-leanix Dec 19, 2020
791db04
bug fix: no update data available
vg-leanix Dec 19, 2020
84ef043
persist taskList to localStorage for smoother UX
vg-leanix Dec 19, 2020
e2dd6c8
enable file sharing between api hub and celery wor
vg-leanix Dec 19, 2020
12c42d5
Merge branch 'master' into v1.1_mongodb
vg-leanix Dec 19, 2020
a01045c
added api call for serving pptx
vg-leanix Dec 20, 2020
97f8c34
optimized build
vg-leanix Dec 20, 2020
24d6e0e
Merge branch 'v1.1_mongodb' of https://github.com/vg-leanix/knowlix i…
vg-leanix Dec 20, 2020
764445e
renamed alert to more succicent naming
vg-leanix Dec 20, 2020
5b9606d
minor bug
vg-leanix Dec 20, 2020
6640ad7
change title to knowlix
vg-leanix Dec 20, 2020
f2a9c8d
plausibilty checks before launching expensive job
vg-leanix Dec 20, 2020
60ac893
notifications for rejections by APIHub
vg-leanix Dec 20, 2020
5ab4cf0
architechture maps
vg-leanix Dec 20, 2020
949cb43
cutting fluff
vg-leanix Dec 21, 2020
fd229fb
inserted new architecture pic
vg-leanix Dec 21, 2020
b13f804
bugfix on README
vg-leanix Dec 21, 2020
c555d0f
headline to readme
vg-leanix Dec 21, 2020
b600667
new architecture map
vg-leanix Dec 21, 2020
44211c8
update
vg-leanix Dec 21, 2020
9ff6ba6
changed yml prod file
vg-leanix Dec 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ data.json
*.pptx
/backend/output
*.pyc
*.log
*.log
mongodb/
db-backup/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@

# knowlix


Microservice to autmatically create onboarding slides

![LIX Builder](https://github.com/vg-leanix/pptx-tool/blob/main/Thumbnail.png)

## Architecture
![Architecture](https://github.com/vg-leanix/knowlix/blob/v1.1_mongodb/knowlix%20architecture.png)
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/
3 changes: 2 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ FROM python:3.8.1

WORKDIR /usr/app


COPY req.txt ./
COPY api.py core.py main.py master.pptx req.txt server.py ./

# RUN mkdir output
RUN mkdir output

RUN pip install --upgrade pip
RUN pip install -r req.txt --no-cache-dir
Expand Down
116 changes: 85 additions & 31 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@
from pptx import Presentation
from server import celery
import json
import uuid
from datetime import datetime
from pymongo import MongoClient


file_path = "master.pptx"
pres= Presentation(file_path)
pres = Presentation(file_path)
MONGODB = os.getenv("MONGODB")
client = MongoClient(MONGODB)
db = client["taskdb"]["ta"]

tags_metadata= [
tags_metadata = [
{
"name": "powerpoint",
"description": "handling powerpoint"
"name": "powerpoint",
"description": "handling powerpoint"
},
{
"name": "job management",
"description": "managing celery tasks"
"name": "job management",
"description": "managing celery tasks"
},

]

app = FastAPI(
title= "SurfBoard",
description= "API Hub for the LeanIX Onboarding Deck",
version= "1.0.0",
title="Knowlix",
description="API Hub for the LeanIX Onboarding Deck",
version="1.0.0",
openapi_tags=tags_metadata)



app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Expand All @@ -43,42 +48,91 @@
expose_headers=[]
)


class PPTX(BaseModel):
sections: List[str]


@app.get("/v1/sections", tags = ["powerpoint"])


class Download(BaseModel):
taskID: str


@app.get("/v1/sections", tags=["powerpoint"])
async def provide_sections():

sections = get_sections(pres)

if (not sections) or (len(sections)==0):
raise HTTPException(status_code=404, detail="No Sections in Master pptx")
if (not sections) or (len(sections) == 0):
raise HTTPException(
status_code=404, detail="No Sections in Master pptx")

return JSONResponse(sections,status_code=200)
return JSONResponse(sections, status_code=200)


@app.post("/v1/pptxjob", tags = ["job management"])
@app.post("/v1/pptxjob", tags=["job management"])
async def deliver_pptx(pptx: PPTX):
task_name = "pptx"
sections = pptx.sections
kwargs ={
'sections':sections,
'downloadStatus': 'ready'
}

no_sections = len(sections)
sections_available = True
exists_already = False
status = None
custom_id = str(uuid.uuid4().hex)
kwargs = {
'sections': sections,
'customID': custom_id,
'downloaded': False

}

if no_sections != 0:
exists_already = check_existence(sections, db)
else:
sections_available = False

if not exists_already and sections_available:
task = celery.send_task(task_name, kwargs=kwargs, serializer='json')

if sections_available and not exists_already:
status = "success"

task = celery.send_task(task_name, kwargs = kwargs, serializer='json')
elif not sections_available:
status = "no_sections"

elif exists_already:
status = "pptx_exists"

package = {
'taskID': task.id,
'sections': sections
'taskID': custom_id,
'sections': sections,
'status': status
}


return JSONResponse(package)






def check_existence(sections, db):
exists_already = False
no_sections = len(sections)
query = {"kwargs.sections": {"$size": no_sections, "$all": sections}}

hits = db.count_documents(query)

if hits > 0:
exists_already = True

return exists_already


@app.post("/v1/download", tags=["powerpoint"])
async def download_pptx(download: Download):

task_id = download.taskID

result = db.find_one({"kwargs.customID": task_id}, {'result': 1, '_id': 0})
unpack = result["result"]
unpack = json.loads(unpack)
file_path = unpack["filePath"]

# return file_path
return FileResponse(file_path)
7 changes: 0 additions & 7 deletions backend/clean_output.py

This file was deleted.

27 changes: 13 additions & 14 deletions backend/req.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
certifi==2020.6.20
click==7.1.2
fastapi==0.61.2
h11==0.11.0
lxml==4.6.1
Pillow==8.0.1
pydantic==1.7.2
python-pptx==0.6.18
starlette==0.13.6
typing==3.7.4.3
uvicorn==0.12.2
XlsxWriter==1.3.7
aiofiles==0.6.0
amqp==5.0.2
billiard==3.6.3.0
celery==5.0.3
certifi==2020.6.20
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
fastapi==0.61.2
h11==0.11.0
kombu==5.0.2
lxml==4.6.1
Pillow==8.0.1
prompt-toolkit==3.0.8
pydantic==1.7.2
pymongo==3.11.2
python-pptx==0.6.18
pytz==2020.4
redis==3.5.3
six==1.15.0
starlette==0.13.6
typing==3.7.4.3
uvicorn==0.12.2
vine==5.0.0
wcwidth==0.2.5
wcwidth==0.2.5
XlsxWriter==1.3.7
8 changes: 6 additions & 2 deletions backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
from celery import Celery

CELERY_BROKER_URL = os.getenv("RABBITMQ")
CELERY_RESULT_BACKEND = os.getenv("REDISSERVER")
CELERY_RESULT_BACKEND = os.getenv("MONGODB")

celery = Celery("worker", backend=CELERY_RESULT_BACKEND, broker=CELERY_BROKER_URL)

celery.conf.update(
result_extended=True
result_extended=True,
mongodb_backend_settings={
'database': 'taskdb',
'taskmeta_collection': 'ta',
}
)
1 change: 1 addition & 0 deletions celery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/
Loading