add files

This commit is contained in:
Mylloon 2024-02-10 14:52:31 +01:00
commit 29f4d0b70a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 49 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.vscode/
*.csv

46
main.py Normal file
View file

@ -0,0 +1,46 @@
import csv
def read_file(path: str, delimiter=","):
res: dict[str, list[str]] = {}
with open(path) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=delimiter)
header = next(csv_reader)
for h in header:
res[h] = []
for row in csv_reader:
for idx, h in enumerate(header):
res[h].append(row[idx])
return res
def count(quantities: dict[str, list[str]], sent: dict[str, list[str]]):
quantites = list(zip(quantities["Item number"], quantities["Nb pdt / carton"]))
envoyes = list(
zip(sent["CodeArticle"], sent["QuantiteCommande"], sent["NumeroCommande"])
)
acc = []
for envoye in envoyes:
for quantite in quantites:
if envoye[0] == quantite[0]: # meme article
if envoye[1] == quantite[1]: # meme quantité
acc.append(envoye)
break
if int(envoye[1]) % int(quantite[1]) == 0: # multiple du carton
acc.append(envoye)
break
return acc
if __name__ == "__main__":
quantites = read_file("quantites.csv")
envoyes = read_file("envoyes.csv", ";")
data = count(quantites, envoyes)
with open("results.csv", "w") as f:
writer = csv.writer(f)
writer.writerow(["Code", "Quantite", "NumeroCommande"])
writer.writerows(data)