| Blockland Forums > Modification Help |
| How do I interface Torque with Python? |
| (1/2) > >> |
| Axolotl:
--- Code: (Python (Nullable's Translator)) ---class Handler(SocketServer.StreamRequestHandler): def handle(self): for line in self.rfile: rq = Request(u"http://translate.google.com/translate_a/t?client=t&text="+quote_plus(latin1_to_ascii(line.strip()))+u"&sl=auto&tl=en") rq.add_header(u"User-Agent", u"Torque/1.0") rs = urlopen(rq) response = rs.read() while ",," in response: response = response.replace(",,", ",\"\",") #response = response.replace("\xC3 ", "\xC3") response = unicode(response, "UTF-8", "ignore") translated = json.loads(response) if translated[2] != "en" and translated[0][0][0] != translated[0][0][1]: self.wfile.write(translated[0][0][0].encode("windows-1252")) self.wfile.write("\r\n") SocketServer.TCPServer(("localhost", 8540), Handler).serve_forever() --- End code --- How do I manipulate the response? I know almost nothing about python so help me with this. |
| Axolotl:
I'll try to manipulate wfile. |
| Axolotl:
I got it to work. Use self.wfile.write("whatever") |
| Brian Smithers:
if you know nothing about python you shouldn't be fiddling with it. |
| Fluff-is-back:
--- Quote from: Brian Smithers on April 13, 2012, 08:01:44 PM ---if you know nothing about python you shouldn't be fiddling with it. --- End quote --- If he knows nothing about python, all the more you should be helping him. Now, I know nothing about python, but a way to get them to interface, I guess could be a TCP listener on blockland, get the python script to connect, then transfer data through that. |
| Navigation |
| Message Index |
| Next page |