Skip to content

Instantly share code, notes, and snippets.

@chun37
Last active August 17, 2017 03:37
Show Gist options
  • Save chun37/921019b3865c6b246b790495441e8bfc to your computer and use it in GitHub Desktop.
Save chun37/921019b3865c6b246b790495441e8bfc to your computer and use it in GitHub Desktop.
横浜市資源循環局のイーオくんとお話できるよ
# -*- coding: utf-8 -*-
import requests
import json
import re
import sys
print u"このプログラムは横浜市資源循環局のイーオくんとお話できるプログラムだよ"
print u"終了したいときは[Ctrl+C]を押すか[/exit]と送ってね"
print u"---" * 20
print u"イーオだよ。こんにちは。"
print u"ゴミの名前を教えてくれたら、捨て方を案内するよ。粗大ごみの手数料を知りたい場合は、「自転車の手数料」のように話しかけてね。"
try:
while 1:
word = raw_input(">>>")
if word == "/exit":
sys.exit(u"またね~")
header = {
"x-api-key": "yVK1QapBTi2kcrsp8izvG3REC9pZash25YM7BYjB",
}
pay = {
"appUserId": "zKOIk4IoDcGeWkEztHYQGW8crB470D2P",
"botId": "yokohamaChatbot",
"voiceText": word,
}
r = requests.post("https://api.repl-ai.jp/v1/dialogue", headers=header, data=json.dumps(pay, encoding='shift-jis'))
print re.sub(re.compile(ur'[\xa5]|[#BTN#]|[#/BTN#]|[n]'), "", r.json()["systemText"]["expression"]).replace("DELIMIER", "\n")
except:
try:
print u"\nまたね~"
sys.exit()
except KeyboardInterrupt:
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment