Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2013 08:10
Show Gist options
  • Save anonymous/6711232 to your computer and use it in GitHub Desktop.
Save anonymous/6711232 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import webapp2
import telnetlib
import time
class MainHandler(webapp2.RequestHandler):
def __utf8_to_big5(self, utf8):
return utf8.decode("utf8").encode("big5")
def __big5_to_utf8(self, big5):
return big5.decode("big5").encode("utf8")
def get(self):
tn = telnetlib.Telnet("ptt.cc")
tn.read_until(self.__utf8_to_big5("註冊"))
tn.write(user + "\r")
tn.read_until(self.__utf8_to_big5("密碼"))
tn.write(password + "\r")
tn.write("\r") #enter in main board
tn.write("S" + "Gossiping" + "\r")
tn.write("\r")
data = tn.read_very_eager()
while data=='':
time.sleep(0.1)
data = tn.read_very_eager()
self.response.write(self.__big5_to_utf8(data))
tn.close()
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment