Browse code

fixed wierd merge issue

Sergey R authored on 21/09/2015 19:14:38
Showing 1 changed files
... ...
@@ -18,17 +18,17 @@ import xml.dom.minidom
18 18
 """
19 19
     chatterbotapi
20 20
     Copyright (C) 2011 pierredavidbelanger@gmail.com
21
-
21
+    
22 22
     This program is free software: you can redistribute it and/or modify
23 23
     it under the terms of the GNU Lesser General Public License as published by
24 24
     the Free Software Foundation, either version 3 of the License, or
25 25
     (at your option) any later version.
26
-
26
+    
27 27
     This program is distributed in the hope that it will be useful,
28 28
     but WITHOUT ANY WARRANTY; without even the implied warranty of
29 29
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30 30
     GNU Lesser General Public License for more details.
31
-
31
+    
32 32
     You should have received a copy of the GNU Lesser General Public License
33 33
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
34 34
 """
... ...
@@ -37,8 +37,6 @@ import xml.dom.minidom
37 37
 # API
38 38
 #################################################
39 39
 
40
-
41
-
42 40
 class ChatterBotType:
43 41
 
44 42
     CLEVERBOT = 1
... ...
@@ -110,158 +108,6 @@ class _CleverbotSession(ChatterBotSession):
110 108
         self.vars['stimulus'] = thought.text
111 109
         data = urlencode(self.vars)
112 110
         data_to_digest = data[9:self.bot.endIndex]
113
-        data_digest = hashlib.md5(data_to_digest).hexdigest()
114
-        data = data + '&icognocheck=' + data_digest
115
-        url_response = self.opener.open(self.bot.serviceUrl, data)
116
-        response = url_response.read()
117
-        response_values = re.split(r'\\r|\r', response)
118
-        #self.vars['??'] = _utils_string_at_index(response_values, 0)
119
-        self.vars['sessionid'] = _utils_string_at_index(response_values, 1)
120
-        self.vars['logurl'] = _utils_string_at_index(response_values, 2)
121
-        self.vars['vText8'] = _utils_string_at_index(response_values, 3)
122
-        self.vars['vText7'] = _utils_string_at_index(response_values, 4)
123
-        self.vars['vText6'] = _utils_string_at_index(response_values, 5)
124
-        self.vars['vText5'] = _utils_string_at_index(response_values, 6)
125
-        self.vars['vText4'] = _utils_string_at_index(response_values, 7)
126
-        self.vars['vText3'] = _utils_string_at_index(response_values, 8)
127
-        self.vars['vText2'] = _utils_string_at_index(response_values, 9)
128
-        self.vars['prevref'] = _utils_string_at_index(response_values, 10)
129
-        #self.vars['??'] = _utils_string_at_index(response_values, 11)
130
-        self.vars['emotionalhistory'] = _utils_string_at_index(response_values, 12)
131
-        self.vars['ttsLocMP3'] = _utils_string_at_index(response_values, 13)
132
-        self.vars['ttsLocTXT'] = _utils_string_at_index(response_values, 14)
133
-        self.vars['ttsLocTXT3'] = _utils_string_at_index(response_values, 15)
134
-        self.vars['ttsText'] = _utils_string_at_index(response_values, 16)
135
-        self.vars['lineRef'] = _utils_string_at_index(response_values, 17)
136
-        self.vars['lineURL'] = _utils_string_at_index(response_values, 18)
137
-        self.vars['linePOST'] = _utils_string_at_index(response_values, 19)
138
-        self.vars['lineChoices'] = _utils_string_at_index(response_values, 20)
139
-        self.vars['lineChoicesAbbrev'] = _utils_string_at_index(response_values, 21)
140
-        self.vars['typingData'] = _utils_string_at_index(response_values, 22)
141
-        self.vars['divert'] = _utils_string_at_index(response_values, 23)
142
-        response_thought = ChatterBotThought()
143
-        response_thought.text = _utils_string_at_index(response_values, 16)
144
-        return response_thought
145
-
146
-#################################################
147
-# Pandorabots impl
148
-#################################################
149
-
150
-class _Pandorabots(ChatterBot):
151
-
152
-    def __init__(self, botid):
153
-        self.botid = botid
154
-
155
-    def create_session(self):
156
-        return _PandorabotsSession(self)
157
-
158
-class _PandorabotsSession(ChatterBotSession):
159
-
160
-    def __init__(self, bot):
161
-        self.vars = {}
162
-        self.vars['botid'] = bot.botid
163
-        self.vars['custid'] = uuid.uuid1()
164
-
165
-    def think_thought(self, thought):
166
-        self.vars['input'] = thought.text
167
-        data = urlencode(self.vars)
168
-        url_response = urlopen('http://www.pandorabots.com/pandora/talk-xml', data)
169
-        response = url_response.read()
170
-        response_dom = xml.dom.minidom.parseString(response)
171
-        response_thought = ChatterBotThought()
172
-        that_elements = response_dom.getElementsByTagName('that')
173
-        if that_elements is None or len(that_elements) == 0 or that_elements[0] is None:
174
-            return ''
175
-        that_elements_child_nodes = that_elements[0].childNodes
176
-        if that_elements_child_nodes is None or len(that_elements_child_nodes) == 0 or that_elements_child_nodes[0] is None:
177
-            return ''
178
-        that_elements_child_nodes_data = that_elements_child_nodes[0].data
179
-        if that_elements_child_nodes_data is None:
180
-            return ''
181
-        response_thought.text = that_elements_child_nodes_data.strip()
182
-        return response_thought
183
-
184
-#################################################
185
-# Utils
186
-#################################################
187
-
188
-def _utils_string_at_index(strings, index):
189
-    if len(strings) > index:
190
-        return strings[index]
191
-    else:
192
-        return ''
193
-
194
-
195
-
196
-    CLEVERBOT = 1
197
-    JABBERWACKY = 2
198
-    PANDORABOTS = 3
199
-
200
-class ChatterBotFactory:
201
-
202
-    def create(self, type, arg = None):
203
-        if type == ChatterBotType.CLEVERBOT:
204
-            return _Cleverbot('http://www.cleverbot.com', 'http://www.cleverbot.com/webservicemin', 35)
205
-        elif type == ChatterBotType.JABBERWACKY:
206
-            return _Cleverbot('http://jabberwacky.com', 'http://jabberwacky.com/webservicemin', 29)
207
-        elif type == ChatterBotType.PANDORABOTS:
208
-            if arg == None:
209
-                raise Exception('PANDORABOTS needs a botid arg')
210
-            return _Pandorabots(arg)
211
-        return None
212
-
213
-class ChatterBot:
214
-
215
-    def create_session(self):
216
-        return None
217
-
218
-class ChatterBotSession:
219
-
220
-    def think_thought(self, thought):
221
-        return thought
222
-
223
-    def think(self, text):
224
-        thought = ChatterBotThought()
225
-        thought.text = text
226
-        return self.think_thought(thought).text
227
-
228
-class ChatterBotThought:
229
-
230
-    pass
231
-
232
-#################################################
233
-# Cleverbot impl
234
-#################################################
235
-
236
-class _Cleverbot(ChatterBot):
237
-
238
-    def __init__(self, baseUrl, serviceUrl, endIndex):
239
-        self.baseUrl = baseUrl
240
-        self.serviceUrl = serviceUrl
241
-        self.endIndex = endIndex
242
-
243
-    def create_session(self):
244
-        return _CleverbotSession(self)
245
-
246
-class _CleverbotSession(ChatterBotSession):
247
-
248
-    def __init__(self, bot):
249
-        self.bot = bot
250
-        self.vars = {}
251
-        self.vars['start'] = 'y'
252
-        self.vars['icognoid'] = 'wsf'
253
-        self.vars['fno'] = '0'
254
-        self.vars['sub'] = 'Say'
255
-        self.vars['islearning'] = '1'
256
-        self.vars['cleanslate'] = 'false'
257
-        self.cookieJar = cookielib.CookieJar()
258
-        self.opener = build_opener(HTTPCookieProcessor(self.cookieJar))
259
-        self.opener.open(self.bot.baseUrl)
260
-
261
-    def think_thought(self, thought):
262
-        self.vars['stimulus'] = thought.text
263
-        data = urlencode(self.vars)
264
-        data_to_digest = data[9:self.bot.endIndex]
265 111
         data_digest = hashlib.md5(data_to_digest.encode('utf-8')).hexdigest()
266 112
         data = data + '&icognocheck=' + data_digest
267 113
         url_response = self.opener.open(self.bot.serviceUrl, data.encode('utf-8'))