コード例 #1
0
ファイル: PyChessFICS.py プロジェクト: Alex-Linhares/pychess
 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)
コード例 #2
0
ファイル: chesspastebin.py プロジェクト: jcoffee/pychess
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()
コード例 #3
0
ファイル: PyChessFICS.py プロジェクト: jcoffee/pychess
 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)
コード例 #4
0
ファイル: Engine.py プロジェクト: vgupta2507/pychess
 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))