示例#1
0
def main(credentials_file, rows):
    """Main entry point."""
    # open the spreadsheet
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        credentials_file, SCOPE)
    gc = gspread.authorize(credentials)
    wks = gc.open("Socios").worksheet('Alta')

    # get the map from spreadsheet titles to colums
    title_values = wks.row_values(TITLE_ROW)
    row_titles = {val: i for i, val in enumerate(title_values)}
    svgfield2col = {}
    for title, svgfield in SVG_FIELDS:
        svgfield2col[svgfield] = row_titles[title]
    data_ok_column = row_titles[DATA_OK_TITLE]

    # build each replace data for each row
    replace_data = []
    for row in rows:
        row_values = wks.row_values(row)

        # check all data is complete
        if row_values[data_ok_column] != "✓":
            raise ValueError("Data is not OK for row {} ({!r})".format(
                row, row_values[data_ok_column]))

        d = {field: row_values[col] for field, col in svgfield2col.items()}
        replace_data.append(d)

    # generate the certificates
    certg.process('carta.svg', 'carta', 'apellido', replace_data)
示例#2
0
    def _generate_letter(self, member):
        """Generate the letter to be signed."""
        letter_svg_template = os.path.join(os.path.dirname(members.__file__),
                                           'templates', 'members', 'carta.svg')
        path_prefix = "/tmp/letter"
        person = member.person
        person_info = {
            'tiposocie': member.category.name,
            'nombre': person.first_name,
            'apellido': person.last_name,
            'dni': person.document_number,
            'email': person.email,
            'nacionalidad': person.nationality,
            'estadocivil': person.marital_status,
            'profesion': person.occupation,
            'fechanacimiento': person.birth_date.strftime("%Y-%m-%d"),
            'domicilio': person.street_address,
            'ciudad': person.city,
            'codpostal': person.zip_code,
            'provincia': person.province,
            'pais': person.country,
        }

        # this could be optimized to generate all PDFs at once, but we're fine so far
        (letter_filepath, ) = certg.process(letter_svg_template,
                                            path_prefix,
                                            "dni", [person_info],
                                            images=None)
        return letter_filepath
示例#3
0
def generate_backs(db):
    """Generate the backs with all the rest of the information."""
    replace_info = []

    for item in db:
        # no point on having both if they are the same
        original_name = item['name_original']
        if original_name == item['name_translated']:
            original_name = ''

        lang_title = "Idioma" if is_single(item['languages']) else "Idiomas"
        demonym_title = "Gentilicio" if is_single(
            item['demonyms']) else "Gentilicios"

        replace_info.append({
            'continent': item['continent'],
            'capital': item['capital_name'],
            'lang_title': lang_title,
            'lang_content': item['languages'],
            'demonym_title': demonym_title,
            'demonym_content': item['demonyms'],
            'codes': item['code'],
            'original_name': original_name,
            'translated_name': item['name_translated'],
            'simple_name': item['name'],
            'wloc_path': item['wloc_path'],
            'progress': item['progress'],
            'reduced_name': item['reduced_name'],
            'idx': item['ridx'],
        })

    image_info = [{
        'placement_rectangle_id': 'rect19351',
        'path_variable': 'wloc_path',
        'placement': 'center',
    }]

    certg.process("card-back.svg",
                  os.path.join(RESULT_DIR, "card-back"),
                  "reduced_name",
                  replace_info,
                  image_info,
                  progress_cb=cback)
示例#4
0
def generate_fronts(db):
    """Generate the fronts with just the flags."""
    replace_info = []
    for item in db:
        replace_info.append({
            'wflag_path': item['wflag_path'],
            'progress': item['progress'],
            'reduced_name': item['reduced_name'],
            'idx': item['ridx'],
        })

    image_info = [{
        'placement_rectangle_id': 'rect19351',
        'path_variable': 'wflag_path',
        'placement': 'center',
    }]

    certg.process("card-front.svg",
                  os.path.join(RESULT_DIR, "card-front"),
                  "reduced_name",
                  replace_info,
                  image_info,
                  progress_cb=cback)
示例#5
0
image_info = [{
    'placement_rectangle_id': 'rect1016',
    'path_variable': 'face_path',
}, {
    'placement_rectangle_id': 'rect1023',
    'path_variable': 'qr_path',
}]

with open("dump-carnets.csv", "rt", encoding="utf8") as fh:
    reader = csv.DictReader(fh)
    for item in reader:
        qr_path = generate_qr(item['last_name'], item['first_name'], item['email'])
        face_path = item['picture']
        if face_path in ("", "False"):  # missing picture, or specifically asked to not have one
            face_path = DEFAULT_FACE
        replace_info.append({
            'nsoc': "{:04d}".format(int(item['legal_id'])),
            'apellido': item['last_name'],
            'nombre': item['first_name'],
            'nick': item['nick'],
            'face_path': os.path.abspath(face_path),
            'qr_path': os.path.abspath(qr_path),
        })


def cback(data):
    print("Avance:", data['nsoc'])


certg.process("carnet-adelante.svg", "socio", "nsoc", replace_info, image_info, progress_cb=cback)