commit 29f4d0b70a678f30c8af3ef052b0512b59cc3dc4 Author: Mylloon Date: Sat Feb 10 14:52:31 2024 +0100 add files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3422af5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/ + +*.csv diff --git a/main.py b/main.py new file mode 100644 index 0000000..e0ccf9c --- /dev/null +++ b/main.py @@ -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)