-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.py
78 lines (54 loc) · 2.36 KB
/
chat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This libray is authored by Tim Keefer here: https://github.com/timotheus/ebaysdk-python
import ebaysdk
import ConfigParser
from ebaysdk.finding import Connection as finding
from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from get_ebay_details import EbayData;
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
# This method is used to get bot responses.
@app.route("/get")
def get_bot_response():
config = ConfigParser.ConfigParser()
config.read("config.cfg")
keywords = config.get("shopping", "list").split(",")
userText = request.args.get('msg')
#Check all words in the config dictionary to see the kind of word.
# for keyword in keywords:
# if keyword in userText:
for keyword in keywords:
if keyword in userText:
return get_ebay_data(config, keyword)
else:
return get_regular_trained_data(userText)
def get_ebay_data(config, keyword):
print "hello"
site_id = config.get('ebay', 'site_id')
app_id = config.get('ebay', 'app_id')
max_price = config.get('ebay', 'max_price')
min_price = config.get('ebay', 'min_price')
sort_order = config.get('ebay', 'sort_order')
api = finding(siteid=site_id,appid=app_id, config_file=None)
response = api.execute('findItemsAdvanced', {
'keywords': keyword,
'itemFilter': [
{'name': 'Condition', 'value': 'Used'},
{'name': 'MinPrice', 'value': min_price, 'paramName': 'Currency', 'paramValue': 'USD'},
{'name': 'MaxPrice', 'value': max_price, 'paramName': 'Currency', 'paramValue': 'USD'}
],
'sortOrder': sort_order
})
item_response = response.dict()
return item_response['itemSearchURL']
# This returns regularly trained based on the query using Chatterbot
def get_regular_trained_data(userText):
english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter")
english_bot.set_trainer(ChatterBotCorpusTrainer)
english_bot.train("chatterbot.corpus.english.greetings")
return str(english_bot.get_response(userText))
if __name__ == "__main__":
app.run()