diff --git a/.github/workflows/pull_request_creation.yml b/.github/workflows/pull_request_creation.yml index 2165605..698474b 100644 --- a/.github/workflows/pull_request_creation.yml +++ b/.github/workflows/pull_request_creation.yml @@ -12,8 +12,6 @@ jobs: fail-fast: false matrix: python-version: - - "3.7" - - "3.8" - "3.9" - "3.10" - "3.11" diff --git a/functions.py b/functions.py index e28322b..022ed75 100644 --- a/functions.py +++ b/functions.py @@ -13,6 +13,26 @@ import sys import textwrap from tqdm import trange +import yaml +import re + + +def generate_download_file_name(yaml_input): + cv_data = load_yaml(yaml_input) + yaml_checker(cv_data) + first_name = cv_data["first_name"] + last_name = cv_data["last_name"] + file_name_formatted = re.sub(" ", "-", f"{first_name}-{last_name}_CV") + print(file_name_formatted) + return file_name_formatted + + +def load_yaml(yaml_input): + if yaml_input: + return yaml.safe_load(yaml_input) + else: + with open("cv_data.yaml", "r") as file: + return yaml.safe_load(file) def cleanup_files(directories: list = ["cv_pages", "cv_images"]): @@ -281,16 +301,15 @@ def generate_pptx_from_pdf( def yaml_checker(yaml): """ - This function is used to assess if the current cv page will be enough - to display the next experience block. If not, a new page should be created. + This function is used to check whether the yaml contains the required fields. """ - assert ( - "first_name" in yaml - ), "'first_name' field is missing in yaml. this is a mandatory field." - assert ( - "last_name" in yaml - ), "'last_name' field is missing in yaml. this is a mandatory field." + assert yaml[ + "first_name" + ], "'first_name' field is missing in yaml. this is a mandatory field." + assert yaml[ + "last_name" + ], "'last_name' field is missing in yaml. this is a mandatory field." assert "role" in yaml, "'role' field is missing in yaml. this is a mandatory field." assert ( "email" in yaml diff --git a/generate_cv.py b/generate_cv.py index 9d9079a..83d7122 100644 --- a/generate_cv.py +++ b/generate_cv.py @@ -3,7 +3,6 @@ from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont from reportlab.pdfgen import canvas -import yaml def generate_cv(yaml_input: str = None, image=None): @@ -11,11 +10,7 @@ def generate_cv(yaml_input: str = None, image=None): cleanup_files(directories=["cv_pages", "cv_images"]) ## LOAD YAML - if yaml_input: - cv_data = yaml.safe_load(yaml_input) - else: - with open("cv_data.yaml", "r") as file: - cv_data = yaml.safe_load(file) + cv_data = load_yaml(yaml_input) ## ASSERT MANDATORY FIELDS IN YAML yaml_checker(cv_data) diff --git a/requirements.txt b/requirements.txt index 282baf9..b8d169a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -black -pyyaml +black==24.10.0 +pyyaml==6.0.2 reportlab<4.0.0 -streamlit -streamlit-cropper +streamlit==1.39.0 +streamlit-cropper==0.2.2 pre-commit -pypdf +pypdf<5 PyMuPDF>=1.22.0 -python-pptx -tqdm +python-pptx==1.0.2 +tqdm==4.66.5 diff --git a/streamlit_app.py b/streamlit_app.py index 2aa06dc..e4daa2e 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -36,11 +36,15 @@ ## DOWNLOAD BUTTONS with open("cv_output/cv.pdf", "rb") as file: - # st.download_button("Download PDF", file, file_name=f"{cv_data['first_name']}_{cv_data['first_name']}_cv.pdf") - st.sidebar.download_button("Download PDF", file, file_name="cv.pdf") + st.sidebar.download_button( + "Download PDF", file, file_name=f"{generate_download_file_name(yaml_text)}.pdf" + ) with open("cv_output/cv.pptx", "rb") as file: - # st.download_button("Download PDF", file, file_name=f"{cv_data['first_name']}_{cv_data['first_name']}_cv.pdf") - st.sidebar.download_button("Download PPTX", file, file_name="cv.pptx") + st.sidebar.download_button( + "Download PPTX", + file, + file_name=f"{generate_download_file_name(yaml_text)}.pptx", + ) ## PDF PREVIEW: need to convert resulting cv.pdf to images, in order to display cv preview on streamlit page dpi = 100