Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import glob
- import os
- from ui.ui_progrressbar import Ui_progressbar_form
- from lib.bridge import Bridge
- from lib.config import ConfigIni
- from lib.export import ExportDBF
- from PyQt5.QtWidgets import QMainWindow, QMessageBox
- from PyQt5.QtCore import Qt
- class ViewExtrairDadosConcorrente(QMainWindow):
- def __init__(self, parent=None):
- super(ViewExtrairDadosConcorrente, self).__init__(parent)
- self.ui_extrair = Ui_progressbar_form()
- self.ui_extrair.setupUi(self)
- self.bridge = Bridge()
- self.config = ConfigIni()
- self.export_dbf = ExportDBF()
- self.range_max = 0
- def create_child_window(self):
- self.setWindowFlags(Qt.Window | Qt.WindowCloseButtonHint)
- self.setWindowTitle("Extrair dados do concorrente")
- self.ui_extrair.info_label.setText("")
- self.range_max = len(self.bridge.instance_object.files_path)
- self.ui_extrair.progressBar.setValue(0)
- self.ui_extrair.iniciar_pushButton.clicked.connect(self.extract_files_concurrent)
- self.ui_extrair.fechar_pushButton.clicked.connect(self.close)
- self.show()
- def extract_files_concurrent(self):
- files_csv_exists = glob.glob(self.config.path_extract_scd + r"*.csv")
- if files_csv_exists:
- qtdade_files_delete = len(files_csv_exists)
- self.range_max = qtdade_files_delete
- self.ui_extrair.progressBar.setRange(0, self.range_max)
- for i, file in enumerate(files_csv_exists):
- self.ui_extrair.info_label.setText(file)
- try:
- os.remove(file)
- self.ui_extrair.progressBar.setValue(i + 1)
- except PermissionError as error:
- error_message = "O arquivo está sendo usado por outro processo.n"
- "Arquivo: {} n"
- "Erro: {}".format(file, error)
- QMessageBox.warning(self, "Erro", error_message)
- self.bridge.instance_object.export_files()
- class Netspeed:
- def __init__(self):
- self.config = ConfigIni()
- # self.database = DataBase()
- self.export = ExportDBF()
- self._dbf_files = self.dbf_files
- self._files_path = self.files_path
- # self.conn = conexao()
- # self.database = DataBase()
- # self._module = self.module
- @property
- def dbf_files(self):
- self._dbf_files = glob.glob(self.config.path_database_concorrente + r"*.dbf")
- return self._dbf_files
- @property
- def files_path(self):
- """
- Propriedade que retorna os arquivos encontrados para conversão com o caminho completo.
- :return: Retorna uma lista com os caminho completo dos arquivos a serem copiados.
- """
- files_list = []
- _files_path = {"socios": glob.glob(self.config.path_database_concorrente + r"netspeed" + "\SOCIOS.dbf"),
- "contador": glob.glob(self.config.path_database_concorrente + r"netspeed" + "\CONTADOR.dbf"),
- "unique": glob.glob(self.config.path_database_concorrente + r"netspeedfls" + "\FLARQDPT.dbf"),
- "folha_FLFU": glob.glob(self.config.path_database_concorrente + r"netspeedfls" + "\FLFU*.DBF"),
- "folha_FLSO": glob.glob(self.config.path_database_concorrente + r"netspeedfls" + "\FLSO*.DBF"),
- "folha_firebird": glob.glob(self.config.path_database_concorrente + r"netspeednetgdb" + "\"
- + "FOLHA.FDB"),
- "folha_interbase": glob.glob(self.config.path_database_concorrente + r"netspeednetgdb" + "\"
- + "FOLHA.GDB"),
- "escrita": glob.glob(self.config.path_database_concorrente + r"netspeedescrita" +
- "\FORCLI.DBF"),
- "contabil_HISTO": glob.glob(self.config.path_database_concorrente + r"netspeedctb" +
- "\HISTO*.dbf"),
- "contabil_PLANO": glob.glob(self.config.path_database_concorrente + r"netspeedctb" +
- "\PLANO*.dbf")}
- for modules in _files_path:
- list_files_module = _files_path.get(modules)
- if list_files_module:
- for i, files_path in enumerate(list_files_module):
- files_list.append(files_path)
- return files_list
- def export_files(self):
- if self.dbf_files:
- for index, file_dbf in enumerate(self.dbf_files):
- file_name = file_dbf.split("\")[-1].split(".")[0]
- table = DBF(file_dbf, ignore_missing_memofile=True, encoding="ANSI", parserclass=MyFieldParser)
- path_csv_file_output = self.config.path_extract_scd + "\" + file_name + ".csv"
- with open(path_csv_file_output, "w", newline='', encoding='utf-8') as csv_file:
- csv_writer = csv.writer(csv_file, delimiter='t')
- csv_writer.writerow(table.field_names)
- for record in table:
- csv_writer.writerow(record.values())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement