<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import csv
import tqdm
import click
from erppeek import Client
from datetime import datetime, date

import configdb

ATR_CASES = ['C2']
ATR_STEPS = ['01']

def create_file(c, from_date, file_output):
    atr_ids = c.GiscedataSwitching.search([('create_date','>=', from_date),('proces_id.name', 'in', ATR_CASES),('step_id.name','in',ATR_STEPS)])

    print "{} contracts found from date {}".format(len(atr_ids), from_date)
    print "Dumping data to {}".format(file_output)

    if not atr_ids:
        print "No ATR cases found"
        return

    polisses = c.GiscedataSwitching.read(atr_ids, ['cups_polissa_id'])
    polisses_ids = set([polissa['cups_polissa_id'][0] for polissa in polisses])

    with open(file_output, 'w') as csvfile:
        fields = ['contrato', 'cups', 'data_alta', 'adr_cups', 'adr_sips', 'poblacio_sips', 'titular', 'titular_email', 'idioma']
        csvwriter = csv.writer(csvfile, quoting=csv.QUOTE_NONNUMERIC ,quotechar ='\"', delimiter=';')
        csvwriter.writerow(fields)
        p_fields = ['name', 'data_alta', 'cups', 'titular']

        for p_data in tqdm.tqdm(c.GiscedataPolissa.read(list(polisses_ids), p_fields)):
            contract_name = p_data['name']
            contract_id = p_data['id']
            cups_id = p_data['cups'][0]
            titular_id = p_data['titular'][0]
            titular_name = p_data['titular'][1]
            cups_name = p_data['cups'][1]

            c_data = c.GiscedataCupsPs.read(cups_id, ['name', 'direccio'])
            t_data = c.ResPartner.read(titular_id, ['name', 'lang', 'vat'])
            pa_ids = c.ResPartnerAddress.search([('partner_id', '=', titular_id)])
            email = ''
            for pa_data in c.ResPartnerAddress.read(pa_ids, ['email']):
                if pa_data['email']:<commit_msg>fix: ignoring contracts without CUPS<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import csv
import tqdm
import click
from erppeek import Client
from datetime import datetime, date

import configdb

ATR_CASES = ['C2']
ATR_STEPS = ['01']

def create_file(c, from_date, file_output):
    atr_ids = c.GiscedataSwitching.search([('create_date','>=', from_date),('proces_id.name', 'in', ATR_CASES),('step_id.name','in',ATR_STEPS)])

    print "{} contracts found from date {}".format(len(atr_ids), from_date)
    print "Dumping data to {}".format(file_output)

    if not atr_ids:
        print "No ATR cases found"
        return

    polisses = c.GiscedataSwitching.read(atr_ids, ['cups_polissa_id'])
    polisses_ids = set([polissa['cups_polissa_id'][0] for polissa in polisses if polissa['cups_polissa_id']])

    with open(file_output, 'w') as csvfile:
        fields = ['contrato', 'cups', 'data_alta', 'adr_cups', 'adr_sips', 'poblacio_sips', 'titular', 'titular_email', 'idioma']
        csvwriter = csv.writer(csvfile, quoting=csv.QUOTE_NONNUMERIC ,quotechar ='\"', delimiter=';')
        csvwriter.writerow(fields)
        p_fields = ['name', 'data_alta', 'cups', 'titular']

        for p_data in tqdm.tqdm(c.GiscedataPolissa.read(list(polisses_ids), p_fields)):
            contract_name = p_data['name']
            contract_id = p_data['id']
            cups_id = p_data['cups'][0]
            titular_id = p_data['titular'][0]
            titular_name = p_data['titular'][1]
            cups_name = p_data['cups'][1]

            c_data = c.GiscedataCupsPs.read(cups_id, ['name', 'direccio'])
            t_data = c.ResPartner.read(titular_id, ['name', 'lang', 'vat'])
            pa_ids = c.ResPartnerAddress.search([('partner_id', '=', titular_id)])
            email = ''
            for pa_data in c.ResPartnerAddress.read(pa_ids, ['email']):
                if pa_data['email']:
{'fraction_non_alphanumeric': 0.15803452855245684, 'fraction_numerical': 0.004780876494023904, 'mean_word_length': 3.394399066511085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1841164', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1370, 'n_words': 259}