minor code cleanup

This commit is contained in:
Lynnesbian 2020-03-08 19:46:07 +10:00
parent d698cd445a
commit 7d718bbe3a
No known key found for this signature in database
GPG Key ID: F0A184B5213D9F90
3 changed files with 11 additions and 9 deletions

2
.gitignore vendored
View File

@ -6,7 +6,7 @@ meme.jpg
toots.db
toots.db-journal
toots.db-wal
__pycache__/*
__pycache__/
.vscode/
.editorconfig
.*.swp

View File

@ -20,17 +20,18 @@ 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
sentence = None

View File

@ -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