Created
December 18, 2012 17:43
-
-
Save jabbalaci/4330179 to your computer and use it in GitHub Desktop.
Alice chat bot
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
#!/usr/bin/env python | |
import requests | |
from bs4 import BeautifulSoup | |
import termcolor | |
BOT_URL = 'http://www.pandorabots.com/pandora/talk?botid=a847934aae3456cb' | |
def main(): | |
print 'Alice Chat Bot 0.1' | |
print 'You can quit with "q".' | |
print '--------------------' | |
while True: | |
try: | |
print termcolor.colored('You:', 'green'), | |
input = raw_input() | |
if input == 'q': | |
break | |
# else | |
payload = {'input': input} | |
r = requests.post(BOT_URL, data=payload) | |
soup = BeautifulSoup(r.text, 'lxml') | |
reply = soup.find('font', {'color': 'darkred'}).text | |
print termcolor.colored('Alice:', 'magenta'), | |
print reply | |
except KeyboardInterrupt: | |
break | |
############################################################################# | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment