1 ====== App Engine ======
3 [[http://code.google.com/appengine/|Google App Engine]]: [[wp>Google_App_Engine|Google App Engine]] \\
8 from google.appengine.ext import webapp
9 from google.appengine.ext.webapp.util import run_wsgi_app
10 from google.appengine.ext import db
12 from HTMLParser import HTMLParser
15 class MyHTMLParser(HTMLParser):
17 HTMLParser.__init__(self)
20 def handle_starttag(self, tag, attrs):
23 if attr[0] == 'flashvars':
27 HTMLParser.feed(self, data)
33 class Level(db.Model):
34 content = db.TextProperty()
36 class Current(db.Model):
37 x = db.IntegerProperty()
38 y = db.IntegerProperty()
39 d = db.IntegerProperty()
40 n = db.IntegerProperty()
41 m = db.IntegerProperty()
42 l = db.IntegerProperty()
44 class Wrong(db.Model):
45 x = db.IntegerProperty()
46 y = db.IntegerProperty()
47 d = db.IntegerProperty()
48 l = db.IntegerProperty()
50 class CrossPage(webapp.RequestHandler):
52 url = 'http://www.hacker.org/cross/index.php?name=kauesilv&password=a1b2c3d4'
53 regex = r'boardinit = "([^"]*)"'
54 debug = self.request.get('debug')
55 s = self.request.get('s')
56 path = self.request.get('path')
57 self.response.headers['Content-Type'] = 'text/plain'
59 urllib.urlopen(url + '&sol=' + path).read()
60 s = urllib.urlopen(url).read()
61 #self.response.out.write(s + '\n')
62 board = re.compile(regex).search(s).groups()[0].split(',')
63 self.response.out.write(str(len(board)) + '\n' + str(len(board[0])) + '\n')
65 self.response.out.write(str(line) + '\n')
67 class MainPage(webapp.RequestHandler):
69 delete = self.request.get('delete')
71 db.delete(Wrong.all().fetch(100))
72 if Wrong.all().count(1) == 1:
75 url = 'http://www.hacker.org/coil/index.php?name=kauesilv&password=a1b2c3d4'
76 regex = r'x=(\d*)&y=(\d*)&board=(.*)'
77 regexLevel = r'Level: (\d*)'
78 self.response.headers['Content-Type'] = 'text/plain'
79 debug = self.request.get('debug')
80 s = self.request.get('s')
81 r = self.request.get('r')
82 x = self.request.get('x')
83 y = self.request.get('y')
84 d = self.request.get('d')
85 w = self.request.get('w')
86 path = self.request.get('path')
89 currents = Current.all()
92 urllib.urlopen(url + '&x=' + x + '&y=' + y + '&path=' + path).read()
99 wrong.l = currents.fetch(1)[0].l
102 if s == '1' or r == '1':
103 s = urllib.urlopen(url).read()
104 x, y, board = re.compile(regex).search(MyHTMLParser().feed(s).get_s()).groups()
105 lvl, = re.compile(regexLevel).search(s).groups()
106 db.delete(Level.all().fetch(1000000))
107 db.delete(Current.all().fetch(1000000))
110 level.content = x + '\n' + y + '\n' + board + '\n'
114 current.x = current.y = current.d = 0
120 cur = currents.fetch(1)[0]
132 wrong = Wrong().gql("WHERE x = :1 AND y = :2 AND d = :3 AND l = :4", cur.x, cur.y, cur.d, cur.l)
133 if(wrong.count(1) == 0):
136 self.response.out.write(str(cur.x) + '\n' + str(cur.y) + '\n' + str(cur.d) + '\n' + str(cur.l) + '\n')
137 self.response.out.write(levels.fetch(1)[0].content)
140 self.response.out.write('\n\n----DEBUG----\n\nwrongs\n')
141 wrongs = Wrong.gql("WHERE l = :1", cur.l)
143 self.response.out.write(str(wrong.x) + ' ' + str(wrong.y) + ' ' + str(wrong.d) + ' ' + str(wrong.l) + '\n')
145 self.response.out.write('\ncurrents\n')
146 for current in currents:
147 self.response.out.write(str(current.x) + ' ' + str(current.y) + ' ' + str(current.d) + ' ' + str(current.l) + '\n')
149 application = webapp.WSGIApplication([('/', MainPage), ('/cross', CrossPage)], debug=True)
152 run_wsgi_app(application)
154 if __name__ == "__main__":