Gravitation wrote:
slinger wrote:
Okay, PHP isn't too hard but it is a little weird at times.
Here is basically what the code would look like (it may need to be edited ):Code:
<html> <head> </head> <body> <?php $chatFile = fopen("chat.txt", "w"); fwrite($chatFile, $_GET['word'].':'. $_GET['reply']); //$_GET gets data from url, I'm using : to separate //the two variables, and reply and word are all taken from the url. fclose($chatFile); </body> </html>Not sure if that's entirely correct, if not I don't doubt that sci or pf will change it for me
Anyway, the URL should look like this "gravi.tation.php?word=Hello&reply=Hey,%20what's%20up?"Ah, okay. Thanks! You're a great programmer.
What code do I put in my Python program?
Nevermind! Thank you so much, slinger. I have a problem, your PHP script erases the whole file before adding the new line.
Offline
Hmm, at least it adds something!
(Sorry about that, I hope you didn't get a huge list going D: )
You could try this (I'm pretty bad at php so don't expect this to work perfectly either :p)
fwrite($chatFile, $chatFile.'\n'.$_GET['word'].':'. $_GET['reply']);
Gravitation wrote:
slinger wrote:
Okay, PHP isn't too hard but it is a little weird at times.
Here is basically what the code would look like (it may need to be edited ):Code:
<html> <head> </head> <body> <?php $chatFile = fopen("chat.txt", "w"); fwrite($chatFile, $_GET['word'].':'. $_GET['reply']); //$_GET gets data from url, I'm using : to separate //the two variables, and reply and word are all taken from the url. fclose($chatFile); </body> </html>Not sure if that's entirely correct, if not I don't doubt that sci or pf will change it for me
Anyway, the URL should look like this "gravi.tation.php?word=Hello&reply=Hey,%20what's%20up?"Ah, okay. Thanks! You're a great programmer.
:')
Last edited by slinger (2012-10-14 09:05:43)
Offline
Don't worry, I'm worse.
And no, I didn't. I tested it in my browser.
Oh, and I put a comment in my code to give credit to you.
But it's still not working, after running
http://gravi.tation.tk/chat.php?word=testing&reply=Cool, you're testing something!
chat.dat is
Resource id #9\ntesting|Cool, you\'re testing something!
Offline
The resource thing is annoying. >.<
Perhaps this would help? Yeah, it's for mySQL problems, but it might be the same method.
Offline
transparent wrote:
The resource thing is annoying. >.<
Perhaps this would help? Yeah, it's for mySQL problems, but it might be the same method.
Thanks, but I'm horrible at that stuff so... I can't figure it out.
Offline
Actually I figured it out.
Thanks guys, here: New version! It's a stand alone Python file, just save it as a .py and chat!
''' Thanks to slinger for showing me how to keep the memory file on my website! ''' import urllib print "Please wait..." known = {} opener = urllib.FancyURLopener({}) chatmem = opener.open("http://gravi.tation.tk/chat.dat") check = chatmem.readlines() for i in check: templ = [] cont = "" for j in i: if j != "|": cont += j else: templ.append(cont) cont = "" templ.append(cont) known[templ[0]] = templ[1] chatmem.close() history = [] print "Chatbot ready. Please type something." while True: ginputd = raw_input() temp = "" for i in ginputd: if i != "," and i != "." and i != "!" and i != "?": temp = temp + str(i).lower() if temp == "show known" or temp == "show history": if temp == "show known": print "" print " Known:" for i in known: print " Reply to \"" + i + "\": \"" + known[i] + "\"" print "" elif temp == "show history": print "" print " History:" for i in history: print " " + i print "" else: history.append("User: " + ginputd) ginputd = False for i in known: if temp.endswith(i): ginputd = i if ginputd != False: print known[ginputd] history.append("Chatbot: " + known[ginputd]) else: print "Whoops, I don't understand that! What would be the appropriate reply?" appr = raw_input() known = {} opener = urllib.FancyURLopener({}) chatmem = opener.open("http://gravi.tation.tk/chat.dat") check = chatmem.readlines() for i in check: templ = [] cont = "" for j in i: if j != "|": cont += j else: templ.append(cont) cont = "" templ.append(cont) known[templ[0]] = templ[1] chatmem.close() chatmem = opener.open("http://gravi.tation.tk/chat.php?word=" + temp + "&reply=" + appr) chatmem.close() known[temp] = appr history.append("Unknown reply, user gives \"" + appr + "\" as correct output.") print "Thanks, I understand now."
Offline
This is still my favourite chatbot:
import random messages = [] while 1: messages.append(raw_input("? ")) print random.choice(messages)
Offline
blob8108 wrote:
This is still my favourite chatbot:
Code:
import random messages = [] while 1: messages.append(raw_input("? ")) print random.choice(messages)
I knew you would post here, since you're a Python programmer.
Offline
Gravitation wrote:
Actually I figured it out.
Thanks guys, here: New version! It's a stand alone Python file, just save it as a .py and chat!Code:
''' Thanks to slinger for showing me how to keep the memory file on my website! ''' import urllib print "Please wait..." known = {} opener = urllib.FancyURLopener({}) chatmem = opener.open("http://gravi.tation.tk/chat.dat") check = chatmem.readlines() for i in check: templ = [] cont = "" for j in i: if j != "|": cont += j else: templ.append(cont) cont = "" templ.append(cont) known[templ[0]] = templ[1] chatmem.close() history = [] print "Chatbot ready. Please type something." while True: ginputd = raw_input() temp = "" for i in ginputd: if i != "," and i != "." and i != "!" and i != "?": temp = temp + str(i).lower() if temp == "show known" or temp == "show history": if temp == "show known": print "" print " Known:" for i in known: print " Reply to \"" + i + "\": \"" + known[i] + "\"" print "" elif temp == "show history": print "" print " History:" for i in history: print " " + i print "" else: history.append("User: " + ginputd) ginputd = False for i in known: if temp.endswith(i): ginputd = i if ginputd != False: print known[ginputd] history.append("Chatbot: " + known[ginputd]) else: print "Whoops, I don't understand that! What would be the appropriate reply?" appr = raw_input() known = {} opener = urllib.FancyURLopener({}) chatmem = opener.open("http://gravi.tation.tk/chat.dat") check = chatmem.readlines() for i in check: templ = [] cont = "" for j in i: if j != "|": cont += j else: templ.append(cont) cont = "" templ.append(cont) known[templ[0]] = templ[1] chatmem.close() chatmem = opener.open("http://gravi.tation.tk/chat.php?word=" + temp + "&reply=" + appr) chatmem.close() known[temp] = appr history.append("Unknown reply, user gives \"" + appr + "\" as correct output.") print "Thanks, I understand now."
Congratulations, I knew you would get it!
Offline
slinger wrote:
Gravitation wrote:
Actually I figured it out.
Thanks guys, here: New version! It's a stand alone Python file, just save it as a .py and chat!Code:
''' Thanks to slinger for showing me how to keep the memory file on my website! ''' import urllib print "Please wait..." known = {} opener = urllib.FancyURLopener({}) chatmem = opener.open("http://gravi.tation.tk/chat.dat") check = chatmem.readlines() for i in check: templ = [] cont = "" for j in i: if j != "|": cont += j else: templ.append(cont) cont = "" templ.append(cont) known[templ[0]] = templ[1] chatmem.close() history = [] print "Chatbot ready. Please type something." while True: ginputd = raw_input() temp = "" for i in ginputd: if i != "," and i != "." and i != "!" and i != "?": temp = temp + str(i).lower() if temp == "show known" or temp == "show history": if temp == "show known": print "" print " Known:" for i in known: print " Reply to \"" + i + "\": \"" + known[i] + "\"" print "" elif temp == "show history": print "" print " History:" for i in history: print " " + i print "" else: history.append("User: " + ginputd) ginputd = False for i in known: if temp.endswith(i): ginputd = i if ginputd != False: print known[ginputd] history.append("Chatbot: " + known[ginputd]) else: print "Whoops, I don't understand that! What would be the appropriate reply?" appr = raw_input() known = {} opener = urllib.FancyURLopener({}) chatmem = opener.open("http://gravi.tation.tk/chat.dat") check = chatmem.readlines() for i in check: templ = [] cont = "" for j in i: if j != "|": cont += j else: templ.append(cont) cont = "" templ.append(cont) known[templ[0]] = templ[1] chatmem.close() chatmem = opener.open("http://gravi.tation.tk/chat.php?word=" + temp + "&reply=" + appr) chatmem.close() known[temp] = appr history.append("Unknown reply, user gives \"" + appr + "\" as correct output.") print "Thanks, I understand now."Congratulations, I knew you would get it!
:') Thanks. Here's the code:
<?php $openfile = fopen ("chat.dat","r") or die (""); $file_size=filesize("chat.dat"); $file_contents = fread ($openfile,$file_size); $writefile = fopen ("chat.dat","w") or die (""); fwrite($writefile, $file_contents. "\n". $_GET['word'].'|'. $_GET['reply']); ?>
Offline
Somebody cussed on it, I've temporarily taken it down.
Offline
And it's back up.
(sorry for the consecutive posts, I can't edit yet)
Offline
slinger wrote:
Yeah, that's one thing I thought about. Maybe have passwords and usernames where you can block people from the chat?
Yeah, but how?
Offline
slinger wrote:
Maybe with databases. But that would require a little bit more PHP :p
I'm scared of databases. ~O~
Offline
They aren't too bad after you get used to them.
Offline
transparent wrote:
They aren't too bad after you get used to them.
That's so with everything, right?
Offline
Gravitation wrote:
transparent wrote:
They aren't too bad after you get used to them.
That's so with everything, right?
Very true.
Offline
Gravitation wrote:
And it's back up.
(sorry for the consecutive posts, I can't edit yet)
Excuse me for being stupid, but where is your website?
Offline
Molybdenum wrote:
Gravitation wrote:
And it's back up.
(sorry for the consecutive posts, I can't edit yet)Excuse me for being stupid, but where is your website?
Gravi.tation.tk
The files are chat.php and chat.dat.
Offline
slinger wrote:
Wow, you're website rocks
Thanks! I've made better, though.
Offline