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
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 <URI> <Database>", 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

View File

@ -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,
@ -48,6 +50,9 @@ for i in range(10):
})
level += 1
if os.getenv("DEBUG") != None:
sys.exit(0)
log("Connecting to database...")
client = pymongo.MongoClient(sys.argv[1])
log("Getting DB...")