Skip to content

Commit

Permalink
Merge pull request #1 from godatadriven/tighten-python-versions
Browse files Browse the repository at this point in the history
Tighten python versions
  • Loading branch information
pgoslatara authored Oct 15, 2024
2 parents d8113de + 6758ae0 commit e5029fc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pull_request_creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand Down
35 changes: 27 additions & 8 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]):
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions generate_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
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):
## CLEANUP FILES
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)
Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 8 additions & 4 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5029fc

Please sign in to comment.