import random import csv pathIntegers : str = "data/row_numbers.csv" pathSentences : str = "data/sentences.csv" pathUrls : str = "data/urls.csv" pathWords : str = "data/words.csv" pathNames : str = "data/names.csv" pathNameModels : str = "data/name_models.csv" pathDates : str = "data/dates.csv" pathColors : str = "data/colors.csv" pathBrands : str = "data/brands.csv" def random_element(pathFile : str) -> str: """ :param pathFile: the relative path of the csv file to read. :return: a random element from this file. """ with open(pathFile) as file: csvList : list = list(csv.reader(file)) random_index_line : int = random.randint(0, len(csvList)) return "" if ( csvList[random_index_line] == [] ) \ else csvList[random_index_line][0] def construct_line(*args : tuple) -> str: """ :param *args: a tuple of elements. example : [ "1", "'toto'", "'Lorem PIPsum'", "42" ]. :return: a line to give to the sql. example : "(1, 'toto', 'Lorem PIPsum', 42)". """ return "(" + ', '.join(list(args)) + ")" def generate_line_acheter() -> str: idMembre : str = random_element(pathIntegers) idPiece : str = random_element(pathIntegers) quantite : str = random_element(pathIntegers) return construct_line(idMembre, idPiece, quantite) def generate_line_avoir_motif() -> str: idPiece : str = random_element(pathIntegers) idMotif : str = random_element(pathIntegers) return construct_line(idPiece, idMotif) def generate_line_avoir_tag() -> str: idTag : str = random_element(pathIntegers) idBoite : str = random_element(pathIntegers) return construct_line(idTag, idBoite) def generate_line_boites() -> str: idBoite : str = random_element(pathIntegers) titre : str = "\'" + random_element(pathWords) + "\'" dateBoite : str = random_element(pathDates) idMarque : str = random_element(pathIntegers) return construct_line(idBoite, titre, dateBoite, idMarque) def generate_line_colorer() -> str: idPiece : str = random_element(pathIntegers) idCouleur : str = random_element(pathIntegers) return construct_line(idPiece, idCouleur) def generate_line_construire() -> str: idBoite : str = random_element(pathIntegers) idModele : str = random_element(pathIntegers) return construct_line(idBoite, idModele) def generate_line_contenir() -> str: idBoite : str = random_element(pathIntegers) idPiece : str = random_element(pathIntegers) quantite : str = random_element(pathIntegers) return construct_line(idBoite, idPiece, quantite) def generate_line_couleurs() -> str: idCouleur : str = random_element(pathIntegers) nomCouleur : str = random_element(pathColors) return construct_line(idCouleur, nomCouleur) def generate_line_enregistrer() -> str: idBoite : str = random_element(pathIntegers) idMembre : str = random_element(pathIntegers) quantite : str = random_element(pathIntegers) return construct_line(idBoite, idMembre, quantite) def generate_line_etre() -> str: idPiece : str = random_element(pathIntegers) idMarque : str = random_element(pathIntegers) return construct_line(idBoite, idMarque) def generate_line_etre_complexe() -> str: idPiece : str = random_element(pathIntegers) idPieceComp : str = random_element(pathIntegers) return construct_line(idPiece, idPieceComp) def generate_line_etre_forme() -> str: idForme : str = random_element(pathIntegers) idPiece : str = random_element(pathIntegers) return construct_line(idForme, idPiece) def generate_line_fils() -> str: idFil : str = random_element(pathIntegers) idModele : str = random_element(pathIntegers) return construct_line(idFil, idModele) def generate_line_illustrations() -> str: idIllustr : str = random_element(pathIntegers) urlIllustr : str = random_element(pathUrls) idModele : str = random_element(pathIntegers) return construct_line(idIllustr, urlIllustr, idModele) def generate_line_marques() -> str: idMarque : str = random_element(pathIntegers) nomMarque : str = random_element(pathBrands) return construct_line(idMarque, nomMarque) def generate_line_membres() -> str: idMembre : str = random_element(pathIntegers) nomMembre : str = random_element(pathNames) return construct_line(idMembre, nomMembre) def generate_line_messages() -> str: idMessages : str = random_element(pathIntegers) contenu : str = random_element(pathSentences) idFil : str = random_element(pathIntegers) idMessages2 : str = random_element(pathIntegers) return construct_line(idMessages, contenu, idFil, idMessages2) def generate_line_modeles() -> str: idModele : str = random_element(pathIntegers) nomModele : str = random_element(pathNameModels) urlNotice : str = random_element(pathUrls) idMembre : str = random_element(pathIntegers) idModeleEte : str = random_element(pathIntegers) return construct_line(idModele, nomModele, urlNotice, idMembre, \ idModeleEte) def generate_line_necessiter() -> str: idModele : str = random_element(pathIntegers) idPiece : str = random_element(pathIntegers) quantite : str = random_element(pathIntegers) return construct_line(idModele, idPiece, quantite) def generate_line_noter() -> str: idModele : str = random_element(pathIntegers) idMembre : str = random_element(pathIntegers) note : str = random_element(pathSentences) return construct_line(idModele, idMembre, note) def generate_line_perdre() -> str: idMembre : str = random_element(pathIntegers) idBoite : str = random_element(pathIntegers) idPiece : str = random_element(pathIntegers) quantite : str = random_element(pathIntegers) return construct_line(idMembre, idBoite, idPiece, quantite) def generate_line_tags() -> str: idTag : str = random_element(pathIntegers) nomTag : str = random_element(pathWords) return construct_line(idTag, nomTag) def generate_line_varier() -> str: idModele_1 : str = random_element(pathIntegers) idModele_2 : str = random_element(pathWords) return construct_line(idModele_1, idModele_2) if __name__ == '__main__': print(generate_line_acheter()) print(generate_line_boites())