2024-08-15 00:39:06 +02:00
|
|
|
"""
|
|
|
|
JSONResume Reader
|
|
|
|
==========
|
|
|
|
|
|
|
|
Version 0
|
|
|
|
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import locale
|
|
|
|
import logging
|
|
|
|
import subprocess
|
2024-08-15 20:12:25 +02:00
|
|
|
import base64
|
2024-08-15 00:39:06 +02:00
|
|
|
from datetime import date
|
|
|
|
from pelican import readers
|
|
|
|
from pelican import signals
|
|
|
|
|
|
|
|
|
|
|
|
class JSONResumeReader(readers.RstReader):
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def read(self, filename):
|
|
|
|
content, metadata = super().read(filename)
|
|
|
|
if not('jsonresume' in metadata and os.path.isfile(metadata['jsonresume'])):
|
|
|
|
raise Exception('please give a jsonresume metadata field for this type')
|
|
|
|
|
|
|
|
metadata['resume'] = json.load(open(metadata['jsonresume']))
|
2024-08-15 20:12:25 +02:00
|
|
|
if 'email' in metadata['resume']['basics']:
|
|
|
|
metadata['resume']['basics']['email'] = base64.b64encode(
|
|
|
|
metadata['resume']['basics']['email'].encode()
|
|
|
|
).decode()
|
2024-08-15 00:39:06 +02:00
|
|
|
metadata['locale'] = self.settings.get('LOCALE', [self.settings.get('DEFAULT_LOCALE', None)])
|
|
|
|
countryname = lambda code: 'langue'
|
|
|
|
|
|
|
|
def setlocale(fct):
|
|
|
|
def wrapped(d):
|
|
|
|
set_locale = self.settings.get('LOCALE', [self.settings.get('DEFAULT_LOCALE', None)])
|
|
|
|
|
|
|
|
if set_locale is not None and len(set_locale) > 0:
|
|
|
|
locale.setlocale(locale.LC_TIME, set_locale[0])
|
|
|
|
|
|
|
|
return fct(d)
|
|
|
|
|
|
|
|
return wrapped
|
|
|
|
|
|
|
|
|
|
|
|
@setlocale
|
|
|
|
def format_date_short(d):
|
|
|
|
return date.fromisoformat(d).strftime('%B %Y').capitalize()
|
|
|
|
|
2024-08-15 06:20:40 +02:00
|
|
|
@setlocale
|
|
|
|
def format_date_year(d):
|
|
|
|
return date.fromisoformat(d).strftime('%Y').capitalize()
|
|
|
|
|
|
|
|
|
2024-08-15 00:39:06 +02:00
|
|
|
format_date_full = lambda d: date.fromisoformat(d).strftime('%d %B %Y').capitalize()
|
|
|
|
isinfinite = lambda d: date.fromisoformat(d).isoformat() == '2999-01-01'
|
|
|
|
metadata['utils'] = {
|
|
|
|
'get_country_name': countryname,
|
|
|
|
'format_date_short': format_date_short,
|
|
|
|
'format_date_full': format_date_full,
|
2024-08-15 06:20:40 +02:00
|
|
|
'format_date_year': format_date_year,
|
2024-08-15 00:39:06 +02:00
|
|
|
'isinfinite': isinfinite
|
|
|
|
}
|
|
|
|
return content, metadata
|
|
|
|
|
|
|
|
|
|
|
|
def add_reader(readers):
|
|
|
|
readers.reader_classes['jsonresume'] = JSONResumeReader
|
|
|
|
|
|
|
|
|
|
|
|
def register():
|
|
|
|
signals.readers_init.connect(add_reader)
|