94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print(generate_line_acheter())
|
|
print(generate_line_boites())
|
|
|