Example #1
0
  def post(self):
    """Handles an HTTP Post to /location. Decodes the location data received
    in post request in JSON format to a Python dictionary object. Stores this
    data into the Location table in the database.    

    Args:
      latitude: CGI Arg Latitude of location to save.
      longitude: CGI Arg Longitude of location to save.
      Name: Name of the user sending the location update.
      
    Returns:
      None.
    """

    #JSONDecoder converts locationJSON to is a python dict object location
    _loc_dict = JSONDecoder().decode(self.request.get("locationJSON"))
    logging.info("This is the location dict passed")
    logging.info(_loc_dict)
    #New STUFF
    #p=_loc_dict["name"]
    #result = db.GqlQuery('select * from Location where name = :1',p  )
    #if result:
    #  for r in result:
    #    r.latitude = float(_loc_dict["latitude"])
    #    r.longitude = float(_loc_dict["longitude"])
    #    r.name=p
    #    r.put()

    #else:
    #End New Stuff


    location = Location(name=str(_loc_dict["name"]),
                        latitude = float(_loc_dict["latitude"]),
                        longitude = float(_loc_dict["longitude"]),
                        TimeandDateFinal=str(_loc_dict["timeanddate"]),
                        UserStatus=str(_loc_dict["status"]),
                        TimeofStatus=str(_loc_dict["timeofstatus"]),
                        )
    
    #location.latitude = float(_loc_dict["latitude"])
    #location.longitude = float(_loc_dict["longitude"])
    #Convert RFC3339 Format date to datetime.datetime object
    #location.date = datetime.datetime.strptime(
    #    _loc_dict["date"], "%Y-%m-%dT%H:%M:%SZ")
    #Store location to database.
    #location.name=str(_loc_dict["name"])
    location.put()
Example #2
0
  def post(self):
    """Handles an HTTP GET to /locations. Retrieves the start and end time
    interval from the querystring parameters and queries the location database
    to retrieve location data between between start and end time. Encodes this
    data to JSON format and sends it in response object.
    
    Args:
      start_time: CGI Arg The min time of the time interval for which
          location updates are retrieved.
      end_time: CGI Arg The max time of the time interval for which
          location updates are retrieved.
      
    Returns:
      A JSONArray holding location data which looks like this:
      [{"latitude": 37.4498306375,
       "date": "2008-06-12 22:59:55",
       "longitude": -122.120338258},
       {"latitude": 37.4493637832, 
       "date": "2008-06-12 23:00:56", 
       "longitude": -122.119523333}]      
    
    """

    #convert RFC 3339 format date to python datetime object
    #start_time = datetime.datetime.strptime(
    #    self.request.get("start_time"), "%Y-%m-%dT%H:%M:%SZ")
    #end_time = datetime.datetime.strptime(
    #    self.request.get("end_time"), "%Y-%m-%dT%H:%M:%SZ")
    
    #get the array of locations reported between _start_time and _end_time
    _name=str(self.request.get("name"))
    #locations = db.GqlQuery(
    #    "SELECT * FROM Location WHERE name = :1",_name)

#date >= :1 and date <= :2 ORDER BY date",


    #callback = self.request.get("jsonp")
    #_loc_JSON = []
    #for location in locations:
    #  if location.latitude:
    #    _loc_JSON.append({"latitude"  : location.latitude
    #        ,"longitude" : location.longitude
    #        ,"name"      : str(location.name)})

    entities = Location().all()
    entities = entities.fetch(10)
    str1=""
    for entity in entities:

        str1=str1+str(entity.name)+ ";" + str(entity.latitude)+ "]"+str(entity.longitude) + "["+ str(entity.TimeandDateFinal) + "+" + str(entity.UserStatus) + "@" + str(entity.TimeofStatus) + "#"
    

    



    #if callback:666666666666
    #  self.response.out.write(
    #      callback + "(" + str(JSONEncoder().encode(_loc_JSON)) + ")")
    #else:
    # self.response.out.write(str(JSONEncoder().encode(_loc_JSON)))
    #self.response.out.write(JSONEncoder().encode(_loc_JSON)))
    self.response.out.write(str1)