scripts: Add and fix the debug flag

This commit is contained in:
Alexander Polynomdivision 2018-10-11 17:25:19 +02:00
parent 6b577273b0
commit feeb07c542
2 changed files with 14 additions and 9 deletions

View File

@ -117,7 +117,7 @@ def csv_to_vocab(filename, type, from_id):
return vocab, id return vocab, id
log("Lateinicus CSV to Vocabulary DB Model") 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("Not enough arguments!", err=True)
log("Usage: csv_vocab_to_mongo.py <URI> <Database>", err=True) log("Usage: csv_vocab_to_mongo.py <URI> <Database>", err=True)
sys.exit(1) sys.exit(1)
@ -145,8 +145,8 @@ log("Adverbs...", tabs=1)
adj, last_id = csv_to_vocab("Adverbien.csv", TYPE_ADVERBS, last_id) adj, last_id = csv_to_vocab("Adverbien.csv", TYPE_ADVERBS, last_id)
vocab += adj vocab += adj
if os.getenv("DEBUG") == None: if os.getenv("DEBUG") != None:
print(vocab) log("{} entries generated".format(len(vocab)))
sys.exit() sys.exit()
# Connect to the database # Connect to the database

View File

@ -2,6 +2,7 @@ import pymongo
import markovify import markovify
import sys import sys
import random import random
import os
def log(msg, err=False, tabs=0): def log(msg, err=False, tabs=0):
if (not err): if (not err):
@ -24,22 +25,23 @@ file.close()
# Create the model using Markov Chains # Create the model using Markov Chains
model = markovify.Text(text) model = markovify.Text(text)
# Generate 10 levels # Generate 25 levels
log("Generating levels...")
levels = [] levels = []
vocab = list(range(1, 100)) vocab = list(range(1, 125))
level = 1 level = 1
for i in range(10): for i in range(25):
name = model.make_short_sentence(50, tries=100) 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 = [] level_vocab = []
# Get random vocabulary # Get random vocabulary
for v in range(4): for v in range(4):
index = random.randint(0, len(vocab)) index = random.randint(0, len(vocab) - 1)
level_vocab.append(index) level_vocab.append(index)
del vocab[index] del vocab[index]
print("{0}: {1} -> {2}".format(level, name, description)) log("Level {}: {}".format(level, name))
levels.append({ levels.append({
"level": level, "level": level,
"name": name, "name": name,
@ -47,6 +49,9 @@ for i in range(10):
"vocab": level_vocab "vocab": level_vocab
}) })
level += 1 level += 1
if os.getenv("DEBUG") != None:
sys.exit(0)
log("Connecting to database...") log("Connecting to database...")
client = pymongo.MongoClient(sys.argv[1]) client = pymongo.MongoClient(sys.argv[1])