updated chatbot with database website

master^2
Alex 7 years ago
parent 74ba3d8c0a
commit 065156e4d9

@ -1,3 +1,3 @@
images/0029.jpg
images/0004.jpg

@ -25,7 +25,7 @@ def cleanedText(text):
#### INDEX (DEPR)
with open('src/index.json', 'w') as f:
with open('src/index.json', 'r') as f:
try:
index = json.load(f)
except:
@ -55,7 +55,7 @@ with open('src/index.json', 'w') as outfile:
######## DATABASE
with open('src/database.json', 'w') as f:
with open('src/database.json') as f:
try:
index = json.load(f)
except:
@ -121,6 +121,8 @@ for n in args.text:
keywordspersentence[key].append({'filename': n, 'sentence': sentence, 'key': key})
print(allcharacters)
if not index:
index["nouns"]=nouns
index["verbs"]=verbs
index["pronouns"]=pronouns
@ -130,6 +132,39 @@ index["keywords"]=keywords
index["keywordspersentence"]=keywordspersentence
index["rawtext"]=alltext
index["chars"] = allcharacters
else:
if not index["nouns"]:
index["nouns"]=nouns
else:
index["nouns"].extend(nouns)
if not index["verbs"]:
index["verbs"]=verbs
else:
index["verbs"].extend(verbs)
if not index["pronouns"]:
index["pronouns"]=pronouns
else:
index["pronouns"].extend(pronouns)
if not index["adverbs"]:
index["adverbs"]=adverbs
else:
index["adverbs"].extend(adverbs)
if not index["adjectives"]:
index["adjectives"]=adjectives
else:
index["adjectives"].extend(adjectives)
if not index["keywords"]:
index["keywords"]=keywords
else:
index["keywords"].extend(keywords)
if not index["keywordspersentence"]:
index["keywordspersentence"]=keywordspersentence
else:
index["keywordspersentence"].update(keywordspersentence)
if not index["chars"]:
index["chars"] = allcharacters
else:
index["chars"].extend(allcharacters)
with open('src/database.json', 'w') as outfile:
json.dump(index, outfile)

File diff suppressed because one or more lines are too long

@ -363,7 +363,7 @@ class HelloBot(irc.bot.SingleServerIRCBot):
c.privmsg(self.channel, "I'm gonna publish this on my twitter account: @ExquisiteChat")
except:
c.privmsg(self.channel, "I wanted to publish this on twitter but I guess it is too long :-(")
self.lastAnswer = "Finished poem"
self.lastAnswer = "towardspoem"
self.poem = []
self.level=0
promt = "Good job, you want to write a new one?"
@ -372,7 +372,7 @@ class HelloBot(irc.bot.SingleServerIRCBot):
elif thispos ==-1:
c.privmsg(self.channel, "You are gonna start this time: give me a {}!".format(STRUCTURE[0]))
self.lastPOS += 1
self.waitingfor=STRUCTURE[1]
self.waitingfor=STRUCTURE[0]
elif thispos == len(STRUCTURE)-1:
word = random.choice(index[STRUCTURE[thispos]+"s"])
c.privmsg(self.channel, "{0}".format(word))
@ -394,7 +394,7 @@ class HelloBot(irc.bot.SingleServerIRCBot):
incoming_msg = e.arguments[0]
self.lastincoming_msg.append(incoming_msg)
analysedincoming = TextBlob(incoming_msg)
print(self.level)
# if incoming_msg == "can you explain again?":
# self.explanation_poem(c,e)
if self.level == -1:
@ -420,9 +420,10 @@ class HelloBot(irc.bot.SingleServerIRCBot):
self.generateASCII(c,e)
answers = ["Are you up for a poem now?"]
msg = random.choice(answers)
self.level = 0
c.privmsg(self.channel,msg)
level=-1
else:
self.level=-1
c.privmsg(self.channel, "Can I help you with any text? Your mood seems ")
if(analysedincoming.sentiment.polarity>0.5):
c.privmsg(self.channel, "very positive. :-D You should definitly write a poem in that mood!")
@ -435,10 +436,10 @@ class HelloBot(irc.bot.SingleServerIRCBot):
self.lastAnswer= "towardspoem"
else:
c.privmsg(self.channel, "This is confusing, what are you doing?")
elif self.level == 1:
if "what is" in incoming_msg:
c.privmsg(self.channel, "A {0} is for example {1}, {2} or {3}".format(self.waitingfor,random.choice(index[self.waitingfor+"s"]),random.choice(index[self.waitingfor+"s"]),random.choice(index[self.waitingfor+"s"])))
elif ("new" in incoming_msg or "change") and "topic" in incoming_msg:

@ -0,0 +1,111 @@
<html>
<head>
<style>
body{
font-family:Helvetica;
}
.contain{
float: left;
width: 14%;
word-wrap:break-word;
height: 90vh;
}
.contain h1{
font-size: 20px;
margin-top: -0px;
padding: 10px;
}
.contain div{
font-size: 9px;
padding-left: 10px;
padding-right: 10px;
overflow: auto;
max-height: 90vh;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="contain" ><h1>nouns</h1><div id="nouns"></div></div>
<div class="contain" ><h1>verbs</h1><div id="verbs"></div></div>
<div class="contain" ><h1>pronouns</h1><div id="pronouns"></div></div>
<div class="contain" ><h1>adverbs</h1><div id="adverbs"></div></div>
<div class="contain" ><h1>adjectives</h1><div id="adjectives"></div></div>
<div class="contain" ><h1>keywords</h1><div id="keywords"></div></div>
<div class="contain" ><h1>chars</h1><div id="chars"></div></div>
<script>
var canUpdate = 1;
$("#nouns, #verbs, #pronouns, #adverbs, #adjectives, #keywords, #chars").scroll(function() {
console.log("scrolling");
canUpdate = 0;
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
// do something
console.log("Haven't scrolled in 250ms!");
canUpdate = 1;
}, 800));
});
$( document ).ready( function () {
if(canUpdate == 1){
var userid = 1,
url = 'database.json',
callback = function (data) {
var nouns = data["nouns"];
var verbs = data["verbs"]
var pronouns = data["pronouns"]
var adverbs = data["adverbs"]
var adjectives = data["adjectives"]
var keywords = data["keywords"]
var chars = data["chars"]
$('#nouns').html(nouns.join("</br>"));
$('#verbs').html(verbs.join("</br>"));
$('#pronouns').html(pronouns.join("</br>"));
$('#adverbs').html(adverbs.join("</br>"));
$('#adjectives').html(adjectives.join("</br>"));
$('#keywords').html(keywords.join("</br>"));
$('#chars').html(chars.join(" "));
var wtf = $('#nouns');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
var wtf = $('#verbs');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
var wtf = $('#pronouns');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
var wtf = $('#adverbs');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
var wtf = $('#adjectives');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
var wtf = $('#keywords');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
var wtf = $('#chars');
var height = wtf[0].scrollHeight;
wtf.scrollTop(height);
console.log("now");
},
fetchData = function () {
$.getJSON(url, callback);
};
fetchData();
setInterval(fetchData, 5000);
}
});
</script>
</body>
</html>
Loading…
Cancel
Save