""" Add books with no ISBN from a csv file """ import requests import random server = "http://localhost:5000/app" IDENTIFIER = "ABC" # TODO : fill in any short identifier def random_isbn(): return IDENTIFIER+"".join([str(random.randint(0, 9)) for _ in range(7)]) def add_book(data): isbn = random_isbn() requests.get(server+f"/submit-isbn?isbn={isbn}&no-search=true") data["isbn"] = isbn r = requests.post(server+"/update-book", data=data) return isbn with open("livres.csv") as f: for line in f: data = [el.strip() for el in line.strip().split(";")] book = { "title": data[0], "author": data[1] if data[1] != "" else "None", "publisher": data[2] if data[2] != "" else "None", "publish_date": data[3] if data[3] != "" else "None", "count": data[4] if data[4] != "" else 1 } if book["title"] in ["Titre", ""]: continue isbn = add_book(book) print(f"Added {book['title']} with isbn {isbn}")