minor code cleanup
This commit is contained in:
parent
d698cd445a
commit
7d718bbe3a
3 changed files with 11 additions and 9 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,7 +6,7 @@ meme.jpg
|
||||||
toots.db
|
toots.db
|
||||||
toots.db-journal
|
toots.db-journal
|
||||||
toots.db-wal
|
toots.db-wal
|
||||||
__pycache__/*
|
__pycache__/
|
||||||
.vscode/
|
.vscode/
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.*.swp
|
.*.swp
|
||||||
|
|
15
functions.py
15
functions.py
|
@ -20,16 +20,17 @@ def make_sentence(output, cfg):
|
||||||
toots = c.execute("SELECT content FROM `toots` ORDER BY RANDOM() LIMIT 10000").fetchall()
|
toots = c.execute("SELECT content FROM `toots` ORDER BY RANDOM() LIMIT 10000").fetchall()
|
||||||
else:
|
else:
|
||||||
toots = c.execute("SELECT content FROM `toots` WHERE cw = 0 ORDER BY RANDOM() LIMIT 10000").fetchall()
|
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.")
|
output.send("Database is empty! Try running main.py.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
model = nlt_fixed(
|
||||||
|
"\n".join([toot[0] for toot in toots])
|
||||||
|
)
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
os.remove("toots-copy.db")
|
||||||
|
|
||||||
toots_str = None
|
toots_str = None
|
||||||
|
|
||||||
|
|
3
main.py
3
main.py
|
@ -83,6 +83,7 @@ db = sqlite3.connect("toots.db")
|
||||||
db.text_factory=str
|
db.text_factory=str
|
||||||
c = db.cursor()
|
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)")
|
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()
|
tableinfo = c.execute("PRAGMA table_info(`toots`)").fetchall()
|
||||||
found = False
|
found = False
|
||||||
|
@ -116,7 +117,7 @@ if not found:
|
||||||
|
|
||||||
c.execute("DROP TABLE `toots`")
|
c.execute("DROP TABLE `toots`")
|
||||||
c.execute("ALTER TABLE `toots_temp` RENAME TO `toots`")
|
c.execute("ALTER TABLE `toots_temp` RENAME TO `toots`")
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def handleCtrlC(signal, frame):
|
def handleCtrlC(signal, frame):
|
||||||
|
|
Loading…
Reference in a new issue