Created
August 30, 2018 01:36
-
-
Save JupyterJones/dceadbc9ead9020ebd8077dd888e4597 to your computer and use it in GitHub Desktop.
ChatterBot Sqlite3 Editor - This will edit the db.sqlite3 file used by chatterbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EDITOR.py | |
print (""" | |
for usage: | |
import EDITOR | |
EDITOR.Help() | |
""") | |
""" | |
EDITOR.View() | |
An input window will open. | |
This prints 100 lines, you provide the starting point | |
and it prints the next 100 lines. | |
Each line starts with the Id number required for editing. | |
-- | |
EDITOR.Find() | |
An input window will open. | |
Enter a term to search for. Each occurance will be displayed | |
whether it be in the text or statement_text. It finds exact occurances. | |
use a word, exact word-pair or exact phrase | |
Each line starts with the Id number required for editing. | |
-- | |
EDITOR.Text() | |
Uses two inputs: | |
you must provide ID and the new Text. | |
It will UPDATE text at id number provided. | |
first input - Insert Id number | |
it will print the input id, the text and the statement_text | |
Then another input will open New Text: | |
Enter the new text. | |
The change will be printed so it can be seen. This verifies the edit. | |
StatementText() | |
Same as the Text() | |
-- | |
EDITOR.Delete() | |
Enter the id to be deleted. | |
-- | |
EDITOR.DeleteRange(): | |
Two inputs will open the Start of the range and the End | |
It deletes The Start through and including the End | |
""" | |
def Help(): | |
Use = """ | |
EDITOR.View() | |
An input window will open. | |
This prints 100 lines, you provide the starting point | |
and it prints the next 100 lines. | |
Each line starts with the Id number required for editing. | |
-- | |
EDITOR.Find() | |
An input window will open. | |
Enter a term to search for. Each occurance will be displayed | |
whether it be in the text or statement_text. It finds exact occurances. | |
use a word, exact word-pair or exact phrase | |
Each line starts with the Id number required for editing. | |
-- | |
EDITOR.Text() | |
Uses two inputs: | |
you must provide ID and the new Text. | |
It will UPDATE text at id number provided. | |
first input - Insert Id number | |
it will print the input id, the text and the statement_text | |
Then another input will open New Text: | |
Enter the new text. | |
The change will be printed so it can be seen. This verifies the edit. | |
StatementText() | |
Same as the Text() | |
-- | |
EDITOR.Delete() | |
Enter the id to be deleted. | |
-- | |
EDITOR.DeleteRange(): | |
Two inputs will open the Start of the range and the End | |
It deletes The Start through and including the End | |
""" | |
print(Use) | |
def View(): | |
count = 0 | |
import sqlite3 | |
conn = sqlite3.connect("db.sqlite3") | |
c = conn.cursor() | |
print("This prints 100 lines, you provide the starting point.") | |
print("Each line starts with the Id number required for editing.") | |
Start = int(input("Start: ")) | |
End = Start + 100 | |
for row in c.execute("SELECT ROWID,* from response"): | |
count = count +1 | |
if count>Start and count<End: | |
print (row[0],row[1],row[2],row[3],row[4],row[5]) | |
print ("Total Lines: ",count) | |
conn.commit() | |
conn.close | |
def Find(): | |
print("Enter a term to search for.") | |
print("Each line starts with the Id number required for editing.") | |
count = 0 | |
import sqlite3 | |
# for experiments conn = sqlite3.connect("db.sqlite3bk") | |
conn = sqlite3.connect("db.sqlite3") | |
c = conn.cursor() | |
search = input("Find: ") | |
for row in c.execute("SELECT ROWID,* from response"): | |
count = count +1 | |
if search in row[2] or search in row[5]: | |
print (row[0],row[1],"\nText: ",row[2],row[3],row[4],"\nStatement_Text: ",row[5]) | |
print (count) | |
def Text(): | |
print("Provide ID and NewText.") | |
Id = input("Insert Id number: ") | |
# UPDATE text at id 1052 | |
import sqlite3 | |
conn = sqlite3.connect('db.sqlite3') | |
c = conn.cursor() | |
for row in c.execute("SELECT ROWID,* from response WHERE rowid = ?",(Id,)): | |
print (row[0],row[1],"\nText: ",row[2],row[3],row[4],"\nStatement_Text: ",row[5]) | |
newtext = input("New Text: ") | |
c.execute("UPDATE response SET text = ? WHERE id= ?", (newtext,Id)) | |
conn.commit() | |
for row in c.execute("SELECT ROWID,* from response WHERE rowid = ?",(Id,)): | |
print (row[0],row[1],"\nText: ",row[2],row[3],row[4],"\nStatement_Text: ",row[5]) | |
conn.close() | |
def StatementText(): | |
print("Provide ID and New Statement_Text.") | |
Id = input("Insert Id number: ") | |
# UPDATE text at id 1052 | |
import sqlite3 | |
conn = sqlite3.connect('db.sqlite3') | |
c = conn.cursor() | |
for row in c.execute("SELECT ROWID,* from response WHERE rowid = ?",(Id,)): | |
print (row[0],row[1],"\nText: ",row[2],row[3],row[4],"\nStatement_Text: ",row[5]) | |
newtext = input("New Text: ") | |
c.execute("UPDATE response SET statement_text = ? WHERE id= ?", (newtext,Id)) | |
conn.commit() | |
for row in c.execute("SELECT ROWID,* from response WHERE rowid = ?",(Id,)): | |
print (row[0],row[1],"\nText: ",row[2],row[3],row[4],"\nStatement_Text: ",row[5]) | |
conn.close() | |
def DeleteRange(): | |
print ("Two inputs will open the Start of the range and the End") | |
print ("It deletes The Start through and including the End") | |
import sqlite3 | |
conn = sqlite3.connect("db.sqlite3") | |
c = conn.cursor() | |
Start = int(input("Start: ")) | |
End = int(input("End: ")) | |
inc = range(Start, End) | |
for rowid in inc: | |
c.execute("DELETE FROM response WHERE rowid = ?", (rowid,)) | |
conn.commit() | |
def Delete(): | |
print ("It deletes Id provided in the input") | |
import sqlite3 | |
conn = sqlite3.connect("db.sqlite3") | |
c = conn.cursor() | |
rowid = int(input("Id: ")) | |
c.execute("DELETE FROM response WHERE rowid = ?", (rowid,)) | |
print (rowid, "Deleted:") | |
conn.commit() | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use in the same directory as the db.sqlite3 used in your chatterbot.