From feeb07c5420163125a08529de7881aba7cd3e316 Mon Sep 17 00:00:00 2001 From: Alexander Polynomdivision Date: Thu, 11 Oct 2018 17:25:19 +0200 Subject: [PATCH] scripts: Add and fix the debug flag --- scripts/csv_vocab_to_mongo.py | 6 +++--- scripts/generate_test_levels.py | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/csv_vocab_to_mongo.py b/scripts/csv_vocab_to_mongo.py index f027697..e2747cd 100644 --- a/scripts/csv_vocab_to_mongo.py +++ b/scripts/csv_vocab_to_mongo.py @@ -117,7 +117,7 @@ def csv_to_vocab(filename, type, from_id): return vocab, id log("Lateinicus CSV to Vocabulary DB Model") -if len(sys.argv) < 3 and os.getenv("DEBUG") != None: +if len(sys.argv) < 3 and os.getenv("DEBUG") == None: log("Not enough arguments!", err=True) log("Usage: csv_vocab_to_mongo.py ", err=True) sys.exit(1) @@ -145,8 +145,8 @@ log("Adverbs...", tabs=1) adj, last_id = csv_to_vocab("Adverbien.csv", TYPE_ADVERBS, last_id) vocab += adj -if os.getenv("DEBUG") == None: - print(vocab) +if os.getenv("DEBUG") != None: + log("{} entries generated".format(len(vocab))) sys.exit() # Connect to the database diff --git a/scripts/generate_test_levels.py b/scripts/generate_test_levels.py index ccebae9..89bab17 100644 --- a/scripts/generate_test_levels.py +++ b/scripts/generate_test_levels.py @@ -2,6 +2,7 @@ import pymongo import markovify import sys import random +import os def log(msg, err=False, tabs=0): if (not err): @@ -24,22 +25,23 @@ file.close() # Create the model using Markov Chains model = markovify.Text(text) -# Generate 10 levels +# Generate 25 levels +log("Generating levels...") levels = [] -vocab = list(range(1, 100)) +vocab = list(range(1, 125)) level = 1 -for i in range(10): +for i in range(25): name = model.make_short_sentence(50, tries=100) - description = ". ".join([model.make_sentence(tries=100) for x in range(4)]) + description = " ".join([model.make_sentence(tries=100) for x in range(4)]) level_vocab = [] # Get random vocabulary for v in range(4): - index = random.randint(0, len(vocab)) + index = random.randint(0, len(vocab) - 1) level_vocab.append(index) del vocab[index] - print("{0}: {1} -> {2}".format(level, name, description)) + log("Level {}: {}".format(level, name)) levels.append({ "level": level, "name": name, @@ -47,6 +49,9 @@ for i in range(10): "vocab": level_vocab }) level += 1 + +if os.getenv("DEBUG") != None: + sys.exit(0) log("Connecting to database...") client = pymongo.MongoClient(sys.argv[1])