def onlineanswer (message): data = urlopen("http://www.pandorabots.com/pandora/talk?botid=8d034368fe360895", urlencode({"message":message, "botcust2":"x"}).encode("utf-8")).read().decode('utf-8') ss = "<b>DMPGirl:</b>" es = "<br>" answer = data[data.find(ss)+len(ss) : data.find(es,data.find(ss))] chatManager.tellPlayer(name, answer)
def paste(gamemodel): output = StringIO() text = pgn.save(output, gamemodel) values = {'apikey': APIKEY, 'pgn': text, "name": "PyChess", 'sandbox': 'false'} data = urlencode(values).encode('utf-8') req = Request(URL, data) try: response = urlopen(req, timeout=10) except URLError as err: if hasattr(err, 'reason'): print('We failed to reach the server.') print('Reason: ', err.reason) elif hasattr(err, 'code'): print('The server couldn\'t fulfill the request.') print('Error code: ', err.code) else: ID = response.read() link = "http://www.chesspastebin.com/?p=%s" % int(ID) clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text(link, -1) #print(text) #print(clipboard.wait_for_text()) msg_dialog = Gtk.MessageDialog(type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK) msg = _( "Game shared at ") + '<a href="%s">chesspastebin.com</a>' % link msg_dialog.set_markup(msg) msg_dialog.format_secondary_text(_("(Link is available on clipboard.)")) msg_dialog.connect("response", lambda msg_dialog, a: msg_dialog.hide()) msg_dialog.show()
def onlineanswer(message): data = urlopen( "http://www.pandorabots.com/pandora/talk?botid=8d034368fe360895", urlencode({"message": message, "botcust2": "x"}).encode("utf-8")).read( ).decode('utf-8') bold_ss = "<b>DMPGirl:</b>" break_es = "<br>" answer = data[data.find(bold_ss) + len(bold_ss):data.find( break_es, data.find(bold_ss))] chatManager.tellPlayer(name, answer)
def answer (message): try: data = urlopen("http://www.pandorabots.com/pandora/talk?botid=8d034368fe360895", urlencode({"message":message, "botcust2":"x"}).encode("utf-8")).read().decode('utf-8') except IOError as e: log.warning("Couldn't answer message from online bot: '%s'" % e, extra={"task":self.defname}) return ss = "<b>DMPGirl:</b>" es = "<br>" answer = data[data.find(ss)+len(ss) : data.find(es,data.find(ss))] self.emit("offer", Offer(CHAT_ACTION, answer))