Created
August 31, 2018 08:31
-
-
Save BlogBlocks/864a45441156d90f8cf6058ba4b80e62 to your computer and use it in GitHub Desktop.
chatterbot MongoDb editor - chatterbot-database
This file contains hidden or 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
from bson.objectid import ObjectId | |
import pymongo | |
import re | |
def textUpdate(): | |
client = pymongo.MongoClient() | |
mydb = myclient["chatterbot-database"] | |
mycol = mydb["statements"] | |
ID = input("ObjectId: ") | |
Id = ObjectId(''+ID+'') | |
TEXT = str(input("text: ")) | |
mycol.update_one({"_id":Id},{'$set':{'text':TEXT}}) | |
return mycol.find_one({"_id":Id})#,{"in_response_to": 1,}) | |
def responseUpdate(): | |
client = pymongo.MongoClient() | |
mydb = myclient["chatterbot-database"] | |
mycol = mydb["statements"] | |
ID = input("ObjectId: ") | |
Id = ObjectId(''+ID+'') | |
TEXT = str(input("text: ")) | |
mycol.update_one({"_id":Id},{'$set':{'in_response_to':TEXT}}) | |
return mycol.find_one({"_id":Id})#,{"in_response_to": 1,}) | |
def Find(): | |
myclient = pymongo.MongoClient("localhost:27017") | |
mydb = myclient["chatterbot-database"] | |
mycol = mydb["statements"] | |
print (mycol) | |
search = input("SEARCH: ") | |
regx = re.compile(search, re.IGNORECASE) | |
mydoc = mycol.find({"text": regx}) | |
count = 0 | |
for x in mydoc: | |
count = count +1 | |
# limit query to 10 responces | |
if count <5: | |
print(x) | |
print("-----------------------------------------------------------------") | |
def DeleteID(): | |
client = pymongo.MongoClient() | |
mydb = myclient["chatterbot-database"] | |
mycol = mydb["statements"] | |
ID = input("ObjectId: ") | |
Id = ObjectId(''+ID+'') | |
mycol.delete_one({'_id': ObjectId(Id)}) | |
def viewLAST(): | |
COUNT = [] | |
myclient = pymongo.MongoClient("localhost:27017") | |
mydb = myclient["chatterbot-database"] | |
mycol = mydb["statements"] | |
count = 0 | |
for x in mycol.find(): | |
count = count +1 | |
# append this count to list COUNT | |
COUNT.append(count) | |
print ("There is a total of :",COUNT[-1],"entries.") | |
print ("View the last N entries into MongoDB.") | |
Num = int(input("Enter Number to View: ")) | |
mycol = mydb["statements"] | |
cont = 0 | |
for x in mycol.find(): | |
cont = cont +1 | |
# COUNT is the total of all documents | |
# if the document count is greater tha all the documents minus 5 | |
#print it | |
if cont < COUNT[Num]: | |
print(x) | |
print ("-----------------------------------------------------------------") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit the database created by chatterbot chatterbot-database