sweemeng avatar sweemeng committed 27c2163

push python version

Comments (0)

Files changed (7)

Binary file added.

Binary file added.

mapgame/action.py

+from google.appengine.ext import webapp
+from google.appengine.api import user
+from google.appengine.ext.webapp.util import run_wsgi_app
+from google.appengine.ext.db import GeoPt
+from django.utils import simplejson as json
+from models import Player
+from models import Location
+
+
+class Position(webapp.RequestHandler):
+    def post(self):
+        user = user.get_current_user()
+        player = Player.get('player =','user')
+        x_point = self.request.get('x_point')
+        y_point = self.request.get('y_point')
+        l = Location()
+        l.x_pt = float(x_point)
+        l.y_pt = float(y_point)
+        l.put()
+        output = []
+        output.append(
+            approximate_post(l.x_pt,l.x_pt-5.0,'x_pt <','x_pt >')
+        )
+        output.append(
+            approximate_post(l.x_pt+5,l.x_pt,'x_pt >','x_pt <')
+        )
+        output.append(
+            approximate_post(l.y_pt,l.y_pt-5.0,'y_pt <','y_pt >')
+        )
+        output.append(
+            approximate_post(l.y_pt+5,l.y_pt,'y_pt >','y_pt <')
+        )
+        self.response.out.write(json.loads(output))     
+        
+def approximate_post(x_pt1,x_pt2,query1,query2)
+    output = []
+    nl = db.Query(Location)
+    nl.filter(query1,x_pt1)
+    nl.filter(query2,x_pt2)
+    for i in nl.fetch(limit=5):
+        temp = {}
+        temp['location'] = i.player.player.email
+        temp['position'] = [i.x_pt,i.y_pt]
+        output.append(temp)
+    return output
+application: mapgame
+version: 1
+runtime: python
+app_version: 1
+
+handlers:
+- url: /position
+  script: position.py

Empty file added.

mapgame/models.py

+from google.appengine.ext import db
+from google.appengine.api import users
+
+
+class Player(db.Model):
+    player = db.UserProperty()
+    hp = db.IntegerProperty()
+    profession = db.StringProperly()
+
+class Location(db.Model):
+    x_pt = db.FloatProperty()
+    y_pt = db.FloatProperty()
+    player = db.ReferenceProperty(Player)
+
+

mapgame/position.py

+from google.appengine.ext import webapp
+from google.appengine.api import user
+from google.appengine.ext.webapp.util import run_wsgi_app
+from google.appengine.ext.db import GeoPt
+from django.utils import simplejson as json
+from models import Player
+from models import Location
+
+
+class Position(webapp.RequestHandler):
+    def post(self):
+        user = user.get_current_user()
+        player = Player.get('player =','user')
+        x_point = self.request.get('x_point')
+        y_point = self.request.get('y_point')
+        l = Location()
+        l.x_pt = float(x_point)
+        l.y_pt = float(y_point)
+        l.put()
+        output = []
+        output.append(
+            approximate_post(l.x_pt,l.x_pt-5.0,'x_pt <','x_pt >')
+        )
+        output.append(
+            approximate_post(l.x_pt+5,l.x_pt,'x_pt >','x_pt <')
+        )
+        output.append(
+            approximate_post(l.y_pt,l.y_pt-5.0,'y_pt <','y_pt >')
+        )
+        output.append(
+            approximate_post(l.y_pt+5,l.y_pt,'y_pt >','y_pt <')
+        )
+        self.response.out.write(json.loads(output))     
+        
+def approximate_post(x_pt1,x_pt2,query1,query2)
+    output = []
+    nl = db.Query(Location)
+    nl.filter(query1,x_pt1)
+    nl.filter(query2,x_pt2)
+    for i in nl.fetch(limit=5):
+        temp = {}
+        temp['location'] = i.player.player.email
+        temp['position'] = [i.x_pt,i.y_pt]
+        output.append(temp)
+    return output
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.