publicando mudanças

This commit is contained in:
João Herculano
2025-08-26 13:57:11 -03:00
parent 05e7958878
commit 846c8e83e6
25 changed files with 13367 additions and 3440 deletions
File diff suppressed because one or more lines are too long
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fd67cc1a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\joao.herculano\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\openpyxl\\worksheet\\_reader.py:329: UserWarning: Unknown extension is not supported and will be removed\n",
" warn(msg)\n",
"c:\\Users\\joao.herculano\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\openpyxl\\worksheet\\_reader.py:329: UserWarning: Unknown extension is not supported and will be removed\n",
" warn(msg)\n",
"c:\\Users\\joao.herculano\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\openpyxl\\worksheet\\_reader.py:329: UserWarning: Unknown extension is not supported and will be removed\n",
" warn(msg)\n",
"c:\\Users\\joao.herculano\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\openpyxl\\worksheet\\_reader.py:329: UserWarning: Unknown extension is not supported and will be removed\n",
" warn(msg)\n"
]
}
],
"source": [
"import os\n",
"import glob\n",
"import pandas as pd\n",
"\n",
"# Directory path\n",
"folder_path = r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\BOT\\Bot - C13\\LANÇAMENTOS\\devolutiva comercial\"\n",
"# Collect files\n",
"file_paths = glob.glob(os.path.join(folder_path, \"*.xls\")) + glob.glob(os.path.join(folder_path, \"*.xlsx\"))\n",
"\n",
"# Required columns\n",
"required_columns = [\"PDV\", \"PRODUTO LANÇAMENTO\", \"SUGESTÃO COMERCIAL\"]\n",
"\n",
"# Load files\n",
"dfs = []\n",
"for file_path in file_paths:\n",
" try:\n",
" df = pd.read_excel(file_path,sheet_name='Sheet1')\n",
" \n",
" missing = [col for col in required_columns if col not in df.columns]\n",
" \n",
" if missing:\n",
" print(f\"Missing columns {missing} ins file: {file_path}\")\n",
" continue # Skip file with missing columns\n",
"\n",
" df[\"source_file\"] = os.path.basename(file_path)\n",
" dfs.append(df)\n",
"\n",
" except Exception as e:\n",
" print(f\"Failed to read {file_path}: {e}\")\n",
"\n",
"# Combine\n",
"if dfs:\n",
" combined_df = pd.concat(dfs, ignore_index=True)\n",
"else:\n",
" print(\"No valid files loaded.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c4c50096",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.int64(82418)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"combined_df['SUGESTÃO COMERCIAL'].isna().sum()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3e1ada65",
"metadata": {},
"outputs": [],
"source": [
"combined_df = combined_df.drop_duplicates()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f5968d9a",
"metadata": {},
"outputs": [],
"source": [
"combined_df['chavers'] = combined_df['PDV'].astype('str') + combined_df['PRODUTO LANÇAMENTO'].astype('str')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fd6a08e7",
"metadata": {},
"outputs": [],
"source": [
"combined_df['chavers'] = combined_df['chavers'].str.replace('.','')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b6eee60e",
"metadata": {},
"outputs": [],
"source": [
"combined_df.to_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\BOT\\Bot - C13\\LANÇAMENTOS\\compilado_comercial_BOTI!!!.xlsx\",index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "84f989f7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
+51
View File
@@ -0,0 +1,51 @@
import pandas as pd
import numpy as np
import os
from datetime import date
def unificador_estoque(pasta_entrada):
hoje = date.today().isoformat()
caminho_saida = os.path.join(pasta_entrada, f"compilado_estoque_{hoje}.xlsx")
print("Salvando em:", caminho_saida)
subpastas = [
os.path.join(pasta_entrada, d)
for d in os.listdir(pasta_entrada)
if os.path.isdir(os.path.join(pasta_entrada, d))
]
df_list = []
for subpasta in subpastas:
arquivos = [f for f in os.listdir(subpasta) if f.endswith(".csv")]
nome_pasta = os.path.basename(subpasta)
for arquivo in arquivos:
caminho_arquivo = os.path.join(subpasta, arquivo)
try:
df = pd.read_csv(caminho_arquivo, encoding="utf-8", low_memory=False)
df["Arquivo_Origem"] = arquivo
df["Pasta_Origem"] = nome_pasta
df_list.append(df)
except Exception as e:
print(f"Erro ao ler o arquivo {arquivo}: {e}")
if not df_list:
raise ValueError("Nenhum arquivo CSV válido foi encontrado.")
df_estoque = pd.concat(df_list, ignore_index=True)
df_estoque["PDV"] = df_estoque["PDV"].astype(str)
df_estoque["SKU_FINAL"] = np.where(
df_estoque["SKU_PARA"] == "-",
df_estoque["SKU"],
df_estoque["SKU_PARA"]
).astype(str)
try:
df_estoque.to_excel(caminho_saida, index=False)
except Exception as e:
raise RuntimeError(f"Erro ao salvar o arquivo Excel: {e}")
return caminho_saida
+71
View File
@@ -0,0 +1,71 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "eba7e63d",
"metadata": {},
"outputs": [],
"source": [
"from compilador_estoque import unificador_estoque\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b59cf803",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Salvando em: C:/Users/joao.herculano/OneDrive - GRUPO GINSENG/Documentos/estoque EUD 14.05\\compilado_estoque_2025-05-14.xlsx\n"
]
},
{
"data": {
"text/plain": [
"'C:/Users/joao.herculano/OneDrive - GRUPO GINSENG/Documentos/estoque EUD 14.05\\\\compilado_estoque_2025-05-14.xlsx'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"unificador_estoque('C:/Users/joao.herculano/OneDrive - GRUPO GINSENG/Documentos/estoque EUD 14.05')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b91d6db",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
@@ -0,0 +1,67 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "967a68c6",
"metadata": {},
"outputs": [],
"source": [
"from datetime import date"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "04e89b60",
"metadata": {},
"outputs": [],
"source": [
"with open(r\"C:\\Users\\joao.herculano\\OneDrive - GRUPO GINSENG\\Ambiente de Trabalho\\acompanhamento improdutivo.csv\",mode='a',newline='',encoding='utf8') as f:\n",
" f.write('DATA;TOTAL_IMPRODUTIVO\\n')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7ef5065f",
"metadata": {},
"outputs": [],
"source": [
"hoje = date.today()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "93c54816",
"metadata": {},
"outputs": [],
"source": [
"with open(r\"C:\\Users\\joao.herculano\\OneDrive - GRUPO GINSENG\\Ambiente de Trabalho\\acompanhamento improdutivo.csv\",mode='a',newline='',encoding='utf8') as f:\n",
" f.write(f'{hoje};2.931.906,29')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff