diff --git a/.gitignore b/.gitignore index 88e9d33..51f90f8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ meme.jpg toots.db toots.db-journal toots.db-wal -__pycache__/* +__pycache__/ .vscode/ .editorconfig .*.swp diff --git a/functions.py b/functions.py index c19fd6c..1921519 100755 --- a/functions.py +++ b/functions.py @@ -20,16 +20,17 @@ def make_sentence(output, cfg): toots = c.execute("SELECT content FROM `toots` ORDER BY RANDOM() LIMIT 10000").fetchall() else: toots = c.execute("SELECT content FROM `toots` WHERE cw = 0 ORDER BY RANDOM() LIMIT 10000").fetchall() - toots_str = "" - for toot in toots: # TODO: find a more efficient way to do this - toots_str += "\n{}".format(toot[0]) - model = nlt_fixed(toots_str) - db.close() - os.remove("toots-copy.db") - if toots_str.rstrip("\n") == "": + if len(toots) == 0: output.send("Database is empty! Try running main.py.") return + + model = nlt_fixed( + "\n".join([toot[0] for toot in toots]) + ) + + db.close() + os.remove("toots-copy.db") toots_str = None diff --git a/main.py b/main.py index 011ef24..b9fe691 100755 --- a/main.py +++ b/main.py @@ -83,6 +83,7 @@ db = sqlite3.connect("toots.db") db.text_factory=str c = db.cursor() c.execute("CREATE TABLE IF NOT EXISTS `toots` (sortid INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, id VARCHAR NOT NULL, cw INT NOT NULL DEFAULT 0, userid VARCHAR NOT NULL, uri VARCHAR NOT NULL, content VARCHAR NOT NULL)") +db.commit() tableinfo = c.execute("PRAGMA table_info(`toots`)").fetchall() found = False @@ -116,7 +117,7 @@ if not found: c.execute("DROP TABLE `toots`") c.execute("ALTER TABLE `toots_temp` RENAME TO `toots`") - + db.commit() def handleCtrlC(signal, frame):