mirror of
https://github.com/AgathaSorceress/mstdn-ebooks.git
synced 2024-11-20 03:25:53 +01:00
minor code cleanup
This commit is contained in:
parent
d698cd445a
commit
7d718bbe3a
2
.gitignore
vendored
2
.gitignore
vendored
@ -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,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
|
||||
|
||||
|
3
main.py
3
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):
|
||||
|
Loading…
Reference in New Issue
Block a user