<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import pdb
import sys
import pickle
import shutil
from datetime import datetime, timedelta
from os import listdir
from os.path import isfile, join
import ConfigParser

# -----------------------------------------------------------------------------
#                                 Parameters:
# -----------------------------------------------------------------------------
cfg_file = 'openerp_s.cfg'
config = ConfigParser.ConfigParser()
config.read(cfg_file)

# -----------------------------------------------------------------------------
# A. SMTP parameter for log mail:
# -----------------------------------------------------------------------------
smtp_server = config.get('smtp', 'server')
smtp_user = config.get('smtp', 'user')
smtp_password = config.get('smtp', 'password')
smtp_port = int(config.get('smtp', 'port'))
smtp_SSL = eval(config.get('smtp', 'SSL'))
from_addr = config.get('smtp', 'from_addr')

# -----------------------------------------------------------------------------
# B. Mexal parameters:
# -----------------------------------------------------------------------------
# mexal_company = config.get('mexal', 'company')
mexal_user = config.get('mexal', 'user')
mexal_password = config.get('mexal', 'password')

# -----------------------------------------------------------------------------
# C. General Parameters:
# -----------------------------------------------------------------------------
price_path = config.get('general', 'price_path')

# -----------------------------------------------------------------------------
# D. Command line parameter:
# -----------------------------------------------------------------------------
try:
    # Setup depend on parameter passed (default SDX if not present)
    company = sys.argv[1]
except:
    company = 'SDX'  # default company

# -----------------------------------------------------------------------------
# E. Company parameter:
# -----------------------------------------------------------------------------
smtp_subject_mask = '%s > %s' % (company, config.get('smtp', 'subject_mask'))
try:
    # Read parameters depend on start up company:
    char_cr = eval(config.get(company, 'return'))  # Return format
    split_file = eval(config.get(company, 'split_file'))  # Split or copy
    post_action = config.get(company, 'post_action')  # Action after import
    update_order = eval(config.get(company, 'update_order'))  # Update order

    if post_action == 'False':
        post_action = False

    # Log file from mexal (empty = OK, else error)
    file_err = config.get(company, 'file_err')
    mexal_company = config.get(company, 'company')
    to_addr = config.get(company, 'to_addr')
    path_in = config.get(company, 'path_in')  # Folder: in files
    path_in_original = os.path.join(path_in, 'original')  # todo create before!
    path_out = config.get(company, 'path_out')  # Folder: destination
    path_history = config.get(company, 'path_history')  # Folder: history
    log_file_name = config.get(company, 'log_file_name')
    sprix_number = config.get(company, 'sprix_number')
    urgent_order = eval(config.get(company, 'urgent_order'))
    # Scheduler log file:
    log_scheduler = config.get(company, 'log_scheduler_name')

    # Jump order too new:
    jump_order_days = eval(config.get(company, 'jump_order_days'))
    left_date_on_file = eval(config.get(company, 'left_date_on_file'))
    left_start_date = int(config.get(company, 'left_start_date'))
    left_days = int(config.get(company, 'left_days'))
    force_file = config.get(company, 'force')
except:
    print(
        '[ERR] Chiamata a ditta non presente '
        '(scelte possibili: SDX o ELI o BIB)')
    sys.exit()  # wrong company!

# -----------------------------------------------------------------------------
# Log files used:
# -----------------------------------------------------------------------------
log_file = open(log_file_name, 'a')
log_schedulers_file = open(log_scheduler, 'a')

# -----------------------------------------------------------------------------
#                           Utility function:
# -----------------------------------------------------------------------------
# A. Price integration setup:
# -----------------------------------------------------------------------------
price_setup = {
    'FAB': {
        'from_code': 162,
        'to_code': 173,  # Load only first 11 char (parent code)
        'separator': '|',
        'partic': {},  # Partic on file
    },
    'HOS': {
        'from_code': 162,
        'to_code': 173,  # Load only first 11 char (parent code)
        'separator': '|',
        'partic': {},  # Partic on file
    },
    'MRK': {
        'from_code': 65,  # todo Wrong position?
        'to_code': 76,  # Load only first 11 char (parent code)
        'separator': '|',
        'partic': {},  # Partic on file
    },
}


def integrate_price(order, order_original, company):
    """ Add price particularity when not present in EDI order
    """
    mail_error = ''
    partic_filename = os.path.join(price_path, '%s.csv' % company)
    # Read particularity once before update:
    setup = price_setup.get(company)  # this company (if present)

    # Check if need integration for price, partic file or setup must be present
    if not setup or not os.path.isfile(partic_filename):
        print('No price integration for %s' % company)
        return mail_error

    # Load particularity file for this operations:
    try:
        if not setup['partic']:
            lines = []
            for line in open(partic_filename):
                lines.append(line)

            # Sort line (last is the new price)
            log_used = open(partic_filename + '.used', 'w')
            for line in sorted(lines):
                log_used.write(line)  # Log operation
                default_code = line[:11].strip()
                price = float(line[-6:].strip().replace(',', '.'))

                # Take last price:
                setup['partic'][default_code] = price<commit_msg>generic bugfix (fast message)<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import pdb
import sys
import pickle
import shutil
from datetime import datetime, timedelta
from os import listdir
from os.path import isfile, join
import ConfigParser

# -----------------------------------------------------------------------------
#                                 Parameters:
# -----------------------------------------------------------------------------
cfg_file = 'openerp_s.cfg'
config = ConfigParser.ConfigParser()
config.read(cfg_file)

# -----------------------------------------------------------------------------
# A. SMTP parameter for log mail:
# -----------------------------------------------------------------------------
smtp_server = config.get('smtp', 'server')
smtp_user = config.get('smtp', 'user')
smtp_password = config.get('smtp', 'password')
smtp_port = int(config.get('smtp', 'port'))
smtp_SSL = eval(config.get('smtp', 'SSL'))
from_addr = config.get('smtp', 'from_addr')

# -----------------------------------------------------------------------------
# B. Mexal parameters:
# -----------------------------------------------------------------------------
# mexal_company = config.get('mexal', 'company')
mexal_user = config.get('mexal', 'user')
mexal_password = config.get('mexal', 'password')

# -----------------------------------------------------------------------------
# C. General Parameters:
# -----------------------------------------------------------------------------
price_path = config.get('general', 'price_path')

# -----------------------------------------------------------------------------
# D. Command line parameter:
# -----------------------------------------------------------------------------
try:
    # Setup depend on parameter passed (default SDX if not present)
    company = sys.argv[1]
except:
    company = 'SDX'  # default company

# -----------------------------------------------------------------------------
# E. Company parameter:
# -----------------------------------------------------------------------------
smtp_subject_mask = '%s > %s' % (company, config.get('smtp', 'subject_mask'))
try:
    # Read parameters depend on start up company:
    char_cr = eval(config.get(company, 'return'))  # Return format
    split_file = eval(config.get(company, 'split_file'))  # Split or copy
    post_action = config.get(company, 'post_action')  # Action after import
    update_order = eval(config.get(company, 'update_order'))  # Update order

    if post_action == 'False':
        post_action = False

    # Log file from mexal (empty = OK, else error)
    file_err = config.get(company, 'file_err')
    mexal_company = config.get(company, 'company')
    to_addr = config.get(company, 'to_addr')
    path_in = config.get(company, 'path_in')  # Folder: in files
    path_in_original = os.path.join(path_in, 'original')  # todo create before!
    path_out = config.get(company, 'path_out')  # Folder: destination
    path_history = config.get(company, 'path_history')  # Folder: history
    log_file_name = config.get(company, 'log_file_name')
    sprix_number = config.get(company, 'sprix_number')
    urgent_order = eval(config.get(company, 'urgent_order'))
    # Scheduler log file:
    log_scheduler = config.get(company, 'log_scheduler_name')

    # Jump order too new:
    jump_order_days = eval(config.get(company, 'jump_order_days'))
    left_date_on_file = eval(config.get(company, 'left_date_on_file'))
    left_start_date = int(config.get(company, 'left_start_date'))
    left_days = int(config.get(company, 'left_days'))
    force_file = config.get(company, 'force')
except:
    print(
        '[ERR] Chiamata a ditta non presente '
        '(scelte possibili: SDX o ELI o BIB)')
    sys.exit()  # wrong company!

# -----------------------------------------------------------------------------
# Log files used:
# -----------------------------------------------------------------------------
log_file = open(log_file_name, 'a')
log_schedulers_file = open(log_scheduler, 'a')

# -----------------------------------------------------------------------------
#                           Utility function:
# -----------------------------------------------------------------------------
# A. Price integration setup:
# -----------------------------------------------------------------------------
price_setup = {
    'FAB': {
        'from_code': 162,
        'to_code': 173,  # Load only first 11 char (parent code)
        'separator': '|',
        'partic': {},  # Partic on file
    },
    'HOS': {
        'from_code': 162,
        'to_code': 173,  # Load only first 11 char (parent code)
        'separator': '|',
        'partic': {},  # Partic on file
    },
    'MRK': {
        'from_code': 65,  # todo Wrong position?
        'to_code': 76,  # Load only first 11 char (parent code)
        'separator': '|',
        'partic': {},  # Partic on file
    },
}


def integrate_price(order, order_original, company):
    """ Add price particularity when not present in EDI order
    """
    mail_error = ''
    partic_filename = os.path.join(price_path, '%s.csv' % company)
    # Read particularity once before update:
    setup = price_setup.get(company)  # this company (if present)

    # Check if need integration for price, partic file or setup must be present
    if not setup or not os.path.isfile(partic_filename):
        print('No price integration for %s' % company)
        return mail_error

    # Load particularity file for this operations:
    try:
        if not setup['partic']:
            lines = []
            for line in open(partic_filename):
                lines.append(line)

            # Sort line (last is the new price)
            # log_used = open(partic_filename + '.used', 'w')
            for line in sorted(lines):
                # log_used.write(line)  # Log operation
                default_code = line[:11].strip()
                price = float(line[-6:].strip().replace(',', '.'))

                # Take last price:
                setup['partic'][default_code] = price
{'fraction_non_alphanumeric': 0.31910001642305796, 'fraction_numerical': 0.004434225652816554, 'mean_word_length': 1.428030303030303, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '225509', 'n_tokens_mistral': 3233, 'n_tokens_neox': 3133, 'n_words': 808}