Skip to content

Instantly share code, notes, and snippets.

@jabbalaci
Created December 18, 2012 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabbalaci/4330179 to your computer and use it in GitHub Desktop.
Save jabbalaci/4330179 to your computer and use it in GitHub Desktop.
Alice chat bot
#!/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:
print
break
#############################################################################
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment