Author Topic: How do I interface Torque with Python?  (Read 709 times)

Code: (Python (Nullable's Translator)) [Select]
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()
How do I manipulate the response? I know almost nothing about python so help me with this.
« Last Edit: April 13, 2012, 06:51:05 PM by Axolotl »

I'll try to manipulate wfile.

I got it to work.
Use self.wfile.write("whatever")

if you know nothing about python you shouldn't be fiddling with it.

if you know nothing about python you shouldn't be fiddling with it.
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.

well
for starters you can learn python ;)
then you can tell us what you want to do with it

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.
in actuality he's doing the inverse in the script he posted
he has the python end hosting a server thingy then blockland is connecting to it