Skip to content

Instantly share code, notes, and snippets.

@BlogBlocks
Created September 2, 2018 02:56
Show Gist options
  • Save BlogBlocks/704c0144f6036ebc7f6c01cbaa297d0d to your computer and use it in GitHub Desktop.
Save BlogBlocks/704c0144f6036ebc7f6c01cbaa297d0d to your computer and use it in GitHub Desktop.
EDITOR.py A chatterbot db.sqlite3 database editor - Very easy to use it can be imported or run: python EDITOR.py
#!/usr/local/bin/python
#EDITOR.py
print ("""
for usage:
import EDITOR
EDITOR.Help()
-------------
also can be used as :
from EDITOR import *
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 StatementText. 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 StatementText
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
--
EDITOR.ViewLast():
Supply the number of lines you wish to view. The last N lines
will be displayed.
--
EDITOR.ViewId()
View by rowid
"""
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 the StatementText. 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 StatementText
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
--
EDITOR.ViewLast():
Supply the number of lines you wish to view. The last N lines
will be displayed.
--
EDITOR.ViewId()
View by rowid
"""
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],"\nStatementText: ",row[5])
print (count)
def Text():
print("Provide ID and NewText.")
Id = input("Insert Id number: ")
# UPDATE text at id 1052
import sqlite3
import sys
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],"\nStatementText: ",row[5])
newtext = input("New Text: ")
if newtext == '':
pass
newtext = newtext.replace(",","\,")
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],"\nStatementText: ",row[5])
print
conn.close()
def StatementText():
print("Provide ID and New StatementText.")
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],"\nStatementText: ",row[5])
newtext = input("New StatementText: ")
newtext = newtext.replace(",","\,")
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],"\nStatementText: ",row[5])
print
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()
def ViewLast():
count = 0
LAST = []
import sqlite3
conn = sqlite3.connect("db.sqlite3")
c = conn.cursor()
print("This prints the last _n entries.")
print("It counts all entries, subtracts the given number and prints.")
last = int(input("The last: "))
for row in c.execute("SELECT ROWID,* from response"):
count = count +1
LAST.append(count)
print ("Total Entries: ",count)
count = 0
for row in c.execute("SELECT ROWID,* from response"):
count = count +1
if count>LAST[-last-1]:
print (row[0],row[1],row[2],row[3],row[4],row[5])
conn.commit()
conn.close
def ViewId():
print("Enter Id number to view")
count = 0
import sqlite3
# for experiments conn = sqlite3.connect("db.sqlite3bk")
conn = sqlite3.connect("db.sqlite3")
c = conn.cursor()
#ID = input("Find: ")
ID = 600
for row in c.execute("SELECT ROWID,* from response WHERE rowid = ?", (ID,)):
row = str(row)
row = row.split(",")
#print (row)
print ("\nROWID: ",row[0][1:],"\nID number: ",row[1],"\nText: ",\
row[2],"\nDate: ",row[3],"\nRank: ",row[4],"\nStatementText: ",row[5][:-1])
def main():
print ("""
Enter number of action to perform:
1 View() Enter rowid - prints the next 100 lines.
2 Find() Enter a term to search for.
Lines also provide Id number required for editing.
3 Text() Requires two inputs: Provide ID and the new Text.
4 StatementText() Same as Text()
5 Delete() Enter the id to be deleted.
6 DeleteRange() Two inputs Start and End range to delete.
7 ViewLast() Supply number, the last N lines will be displayed.
8 ViewId() View by rowid
""")
choice = 0
choice = int(input("Enter Number:"))
if choice == 1:
View()
if choice == 2:
Find()
if choice == 3:
Text()
if choice == 4:
StatementText()
if choice == 5:
Delete()
if choice == 6:
DeleteRange()
if choice == 7:
ViewLast()
if choice == 8:
ViewId()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment