diff options
Diffstat (limited to '')
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | resumejson_converter/filters.py | 38 | ||||
-rw-r--r-- | resumejson_converter/generators/html.py | 8 | ||||
-rw-r--r-- | resumejson_converter/generators/pdf.py | 4 | ||||
-rw-r--r-- | resumejson_converter/utils/json.py | 5 | ||||
-rw-r--r-- | resumejson_converter/utils/templates.py | 5 |
6 files changed, 65 insertions, 1 deletions
@@ -2,6 +2,12 @@ A small package for convert json resume with templating to html and pdf. +WARNING: For the moment the filters are very specific to my template who is not +in this repo at this time. + +WARNING: Many of thing in this code is only in French, like date generation, +phone number or some dates. + # Input About the JSON resume standard: [https://jsonresume.org/schema/](https://jsonresume.org/schema/). diff --git a/resumejson_converter/filters.py b/resumejson_converter/filters.py index f15ee63..fcc4dfa 100644 --- a/resumejson_converter/filters.py +++ b/resumejson_converter/filters.py @@ -5,6 +5,26 @@ import resumejson_converter.utils.templates as utemplates def dateedit(startDate, endDate): + """ + Return the date in special format. + + If only the start date is specified: 2019 - Auj. + + >>> dateedit("2019-01-01") + "2019 - Auj." + + Else if the year of the start date and the year of the end data are the + same: 2019 + + >>> dateedit("2019-01-01", "2019-02-02") + "2019" + + Else if the year of start date are not the same that the year of the end + date: 2017 - 2019 + + >>> datetime("2019-01-01", "2017-05-01") + "2019 - 2017" + """ startDateTime = datetime.strptime(startDate, '%Y-%m-%d') if endDate == "": return "{:%Y} - Auj.".format(startDateTime) @@ -18,6 +38,12 @@ def dateedit(startDate, endDate): def datediff(title, startDate, endDate, showDiff=True): + """ + Return time passed between two dates after a text. + + >>> datediff("Hello World", "2019-01-02", "2019-06-02") + 'Hello World - 5 mois' + """ if showDiff and endDate != "": startDateTime = datetime.strptime(startDate, '%Y-%m-%d') endDateTime = datetime.strptime(endDate, '%Y-%m-%d') @@ -29,10 +55,22 @@ def datediff(title, startDate, endDate, showDiff=True): def birthday(date): + """ + Return a date in french format. + + >>> birthday("1990-10-25") + '25 octobre 1990' + """ date = datetime.strptime(date, '%Y-%m-%d') return format_date(date, format='long', locale='fr') def clean(phone): + """ + Return phone number in french format. + + >>> clean("0011223344") + '00 11 22 33 44' + """ phone = [phone[num:num+2] for num in range(0, len(phone), 2)] return " ".join(phone) diff --git a/resumejson_converter/generators/html.py b/resumejson_converter/generators/html.py index 57df871..1b34e91 100644 --- a/resumejson_converter/generators/html.py +++ b/resumejson_converter/generators/html.py @@ -9,6 +9,14 @@ import resumejson_converter.filters as filters def generate(resume, template, out_path): + """ + Return html version of a JSON resume based on a template. + + `resume` is a JsonObject from resumejson_converter.utils.json. + `template` is the path of the template to use. + `out_path` is the output path of html generate. By default the html is + not writen in a file. + """ try: logging.info("HTML generation...") templates_path = path.dirname(template) diff --git a/resumejson_converter/generators/pdf.py b/resumejson_converter/generators/pdf.py index de3e880..b8c2905 100644 --- a/resumejson_converter/generators/pdf.py +++ b/resumejson_converter/generators/pdf.py @@ -5,6 +5,10 @@ import pdfkit def generate(html): + """ + Generate a pdf file in out/out.pdf in current folder where main script + is executed. + """ logging.info("PDF generation...") pdf_output_path = "out/out.pdf" diff --git a/resumejson_converter/utils/json.py b/resumejson_converter/utils/json.py index f3ce3d1..77e1312 100644 --- a/resumejson_converter/utils/json.py +++ b/resumejson_converter/utils/json.py @@ -8,6 +8,8 @@ from jsonresume.exceptions import InvalidResumeError class JsonObject(object): """ + Simple JSON object. + All work for this function go to https://dev.to/mandrewcito/nested-json-to-python-object--5ajp """ @@ -27,6 +29,9 @@ class JsonObject(object): def load(json_filepath): + """ + Return a JsonObject from resumejson_converter.utils.json. + """ try: logging.info("JSON parsing...") with open(json_filepath, 'r') as f: diff --git a/resumejson_converter/utils/templates.py b/resumejson_converter/utils/templates.py index b22b4b2..a034103 100644 --- a/resumejson_converter/utils/templates.py +++ b/resumejson_converter/utils/templates.py @@ -2,7 +2,10 @@ def td_format(td_object): """ - based on https://stackoverflow.com/a/13756038 + Return time in `An, Mois, Semaine, Jour, Heure, Minute, Seconde` format. + Only in french. + + Based on https://stackoverflow.com/a/13756038 """ seconds = int(td_object.total_seconds()) periods = [ |