Added assertions to make sure csv data is correctly formatted (fixes #8)

This commit is contained in:
Felix Ableitner 2019-11-10 17:34:05 +01:00
parent f43c94c626
commit 263bcf0870

View file

@ -53,6 +53,14 @@ for root, dirs, files in os.walk('quotes/'):
csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='`', skipinitialspace=True)
quotes += list(csvreader)
for q in quotes:
# Check correct number of fields
assert (len(q) == 4), "Error: wrong number of fields in " + str(q)
# Check correct field names
assert ('quote' in q and 'author' in q and 'link' in q and 'linktitle' in q), "Error: missing field in " + str(q)
# Check that no field is empty
assert (q['quote'] and q['author'] and q['link'] and q['linktitle']), "Error: empty field in " + str(q)
print(f"Found {len(quotes)} total quotes")
row = random.choice(quotes)