minor code cleanup
This commit is contained in:
parent
d698cd445a
commit
7d718bbe3a
|
@ -6,7 +6,7 @@ meme.jpg
|
|||
toots.db
|
||||
toots.db-journal
|
||||
toots.db-wal
|
||||
__pycache__/*
|
||||
__pycache__/
|
||||
.vscode/
|
||||
.editorconfig
|
||||
.*.swp
|
||||
|
|
15
functions.py
15
functions.py
|
@ -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
|
||||
|
|
1
main.py
1
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
|
||||
|
|
Loading…
Reference in New Issue