<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright (C) 2013-Today  <NAME> - CLVsol
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

from __future__ import print_function

import sqlite3
import re


def person_export_sqlite(client, args, db_path, table_name):

    conn = sqlite3.connect(db_path)
    conn.text_factory = str

    cursor = conn.cursor()
    try:
        cursor.execute('''DROP TABLE ''' + table_name + ''';''')
    except Exception as e:
        print('------->', e)
    cursor.execute(
        '''
        CREATE TABLE ''' + table_name + ''' (
            id INTEGER NOT NULL PRIMARY KEY,
            tag_ids,
            category_ids,
            name,
            alias,
            code,
            user_id,
            gender,
            marital,
            birthday,
            estimated_age,
            spouse_id,
            father_id,
            mother_id,
            responsible_id,
            identification_id,
            otherid,
            rg,
            cpf,
            country_id,
            date_inclusion,
            state,
            notes,
            address_id,
            is_patient,
            active,
            active_log,
            new_id INTEGER
            );
        '''
    )

    person_model = client.model('myo.person')
    person_browse = person_model.browse(args)

    person_count = 0
    for person_reg in person_browse:
        person_count += 1

        print(person_count, person_reg.id, person_reg.code, person_reg.name.encode("utf-8"))

        alias = None
        if person_reg.alias:
            alias = person_reg.alias

        user_id = None
        if person_reg.user_id:
            user_id = person_reg.user_id.id

        birthday = None
        if person_reg.birthday:
            birthday = person_reg.birthday

        estimated_age = None
        if person_reg.estimated_age:
            estimated_age = person_reg.estimated_age

        marital = None
        if person_reg.marital:
            marital = person_reg.marital

        spouse_id = None
        if person_reg.spouse_id:
            spouse_id = person_reg.spouse_id.id

        father_id = None
        if person_reg.father_id:
            father_id = person_reg.father_id.id

        mother_id = None
        if person_reg.mother_id:
            mother_id = person_reg.mother_id.id

        responsible_id = None
        if person_reg.responsible_id:
            responsible_id = person_reg.responsible_id.id

        identification_id = None
        if person_reg.identification_id:
            identification_id = person_reg.identification_id

        otherid = None
        if person_reg.otherid:
            otherid = person_reg.otherid

        rg = None
        if person_reg.rg:
            rg = person_reg.rg

        cpf = None
        if person_reg.cpf:
            cpf = person_reg.cpf

        country_id = None
        if person_reg.country_id:
            country_id = person_reg.country_id.id

        notes = None
        if person_reg.notes:
            notes = person_reg.notes

        cursor.execute('''
            INSERT INTO ''' + table_name + '''(
                id,
                tag_ids,
                category_ids,
                name,
                alias,
                code,
                user_id,
                gender,
                marital,
                birthday,
                estimated_age,
                spouse_id,
                father_id,
                mother_id,
                responsible_id,
                identification_id,
                otherid,
                rg,
                cpf,
                country_id,
                date_inclusion,
                state,
                notes,
                address_id,
                is_patient,
                active,
                active_log
                )
            VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
            ''', (person_reg.id,
                  str(person_reg.tag_ids.id),
                  str(person_reg.category_ids.id),
                  person_reg.name,
                  alias,
                  person_reg.code,
                  user_id,
                  person_reg.gender,
                  marital,
                  birthday,
                  estimated_age,
                  spouse_id,
                  father_id,
                  mother_id,
                  responsible_id,
                  identification_id,
                  otherid,
                  rg,
                  cpf,
                  country_id,
                  person_reg.date_inclusion,
                  person_reg.state,
                  notes,
                  person_reg.address_id.id,
                  person_reg.is_patient,
                  person_reg.active,
                  person_reg.active_log,
                  )
        )

    conn.commit()
    conn.close()

    print()
    print('--> person_count: ', person_count)

<commit_msg>[IMP] myo_person.py<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright (C) 2013-Today  <NAME> - CLVsol
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

from __future__ import print_function

import sqlite3
import re


def person_export_sqlite(client, args, db_path, table_name):

    conn = sqlite3.connect(db_path)
    conn.text_factory = str

    cursor = conn.cursor()
    try:
        cursor.execute('''DROP TABLE ''' + table_name + ''';''')
    except Exception as e:
        print('------->', e)
    cursor.execute(
        '''
        CREATE TABLE ''' + table_name + ''' (
            id INTEGER NOT NULL PRIMARY KEY,
            tag_ids,
            category_ids,
            name,
            alias,
            code,
            random_field,
            user_id,
            gender,
            marital,
            birthday,
            estimated_age,
            spouse_id,
            father_id,
            mother_id,
            responsible_id,
            identification_id,
            otherid,
            rg,
            cpf,
            country_id,
            date_inclusion,
            state,
            notes,
            address_id,
            is_patient,
            active,
            active_log,
            new_id INTEGER
            );
        '''
    )

    person_model = client.model('myo.person')
    person_browse = person_model.browse(args)

    person_count = 0
    for person_reg in person_browse:
        person_count += 1

        print(person_count, person_reg.id, person_reg.code, person_reg.name.encode("utf-8"))

        alias = None
        if person_reg.alias:
            alias = person_reg.alias

        user_id = None
        if person_reg.user_id:
            user_id = person_reg.user_id.id

        birthday = None
        if person_reg.birthday:
            birthday = person_reg.birthday

        estimated_age = None
        if person_reg.estimated_age:
            estimated_age = person_reg.estimated_age

        marital = None
        if person_reg.marital:
            marital = person_reg.marital

        spouse_id = None
        if person_reg.spouse_id:
            spouse_id = person_reg.spouse_id.id

        father_id = None
        if person_reg.father_id:
            father_id = person_reg.father_id.id

        mother_id = None
        if person_reg.mother_id:
            mother_id = person_reg.mother_id.id

        responsible_id = None
        if person_reg.responsible_id:
            responsible_id = person_reg.responsible_id.id

        identification_id = None
        if person_reg.identification_id:
            identification_id = person_reg.identification_id

        otherid = None
        if person_reg.otherid:
            otherid = person_reg.otherid

        rg = None
        if person_reg.rg:
            rg = person_reg.rg

        cpf = None
        if person_reg.cpf:
            cpf = person_reg.cpf

        country_id = None
        if person_reg.country_id:
            country_id = person_reg.country_id.id

        notes = None
        if person_reg.notes:
            notes = person_reg.notes

        cursor.execute('''
            INSERT INTO ''' + table_name + '''(
                id,
                tag_ids,
                category_ids,
                name,
                alias,
                code,
                random_field,
                user_id,
                gender,
                marital,
                birthday,
                estimated_age,
                spouse_id,
                father_id,
                mother_id,
                responsible_id,
                identification_id,
                otherid,
                rg,
                cpf,
                country_id,
                date_inclusion,
                state,
                notes,
                address_id,
                is_patient,
                active,
                active_log
                )
            VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
            ''', (person_reg.id,
                  str(person_reg.tag_ids.id),
                  str(person_reg.category_ids.id),
                  person_reg.name,
                  alias,
                  person_reg.code,
                  person_reg.random_field,
                  user_id,
                  person_reg.gender,
                  marital,
                  birthday,
                  estimated_age,
                  spouse_id,
                  father_id,
                  mother_id,
                  responsible_id,
                  identification_id,
                  otherid,
                  rg,
                  cpf,
                  country_id,
                  person_reg.date_inclusion,
                  person_reg.state,
                  notes,
                  person_reg.address_id.id,
                  person_reg.is_patient,
                  person_reg.active,
                  person_reg.active_log,
                  )
        )

    conn.commit()
    conn.close()

    print()
    print('--> person_count: ', person_count)


{'fraction_non_alphanumeric': 0.1026236559139785, 'fraction_numerical': 0.00189247311827957, 'mean_word_length': 1.3673386275707595, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677718', 'n_tokens_mistral': 3206, 'n_tokens_neox': 3007, 'n_words': 702}