Ejemplo n.º 1
0
 def get(self,hunt_key):
   hunt = db.get(hunt_key)
   session = get_current_session()
   if session.has_key('user'):
     user = session["user"]
     hunt_player = HuntPlayer.all().filter("user",user).filter("hunt",hunt).fetch(1)
     if len(hunt_player) == 0:
       hunt_player = HuntPlayer(user=user,hunt=hunt)
       hunt_player.put()
       alertPlayer(hunt_player, "Thanks for joining the hunt. Good luck!")
       alertAllPlayersButMe(hunt_player, hunt, hunt_player.user.first_name + " just joined the hunt!")
     self.redirect("/" + hunt_key)
   else:
     self.redirect("/login?hunt_key="+hunt_key)
Ejemplo n.º 2
0
  def post(self):
    checkin_info = json.loads(self.request.get("checkin"))
    user_id      = checkin_info["user"]["id"]
    venue_id     = checkin_info["venue"]["id"]

    # get user and venue, if we don't have a valid one, we don't care about this check in
    user = User.all().filter("foursquare_id", user_id).fetch(1)
    # Safeguard 
    if len(user) == 0:
      return
    user = user[0]

    for player in user.playing_hunts:
      # TODO, check if the hunt is active
      venue = HuntVenue.all().filter("foursquare_id", venue_id).filter("hunt", player.hunt).fetch(1)

      if len(venue) == 1:
        venue = venue[0]
        # We need to make sure the user has not been on this location before
        hunt = player.hunt
        hunt_checkin = HuntCheckin.all().filter("player", player).filter("hunt", hunt).filter("venue", venue).fetch(1)

        if len(hunt_checkin) == 0:
          hunt_checkin = HuntCheckin(player = player, hunt = hunt, venue=venue, foursquare_id=checkin_info["id"])
          # TODO add some metadata from foursquare
          hunt_checkin.put()

          points_word = "point"
          if hunt_checkin.venue.difficulty > 1:
            points_word = "points"
          alertPlayer(player, "You found a checkpoint worth " + str(hunt_checkin.venue.difficulty) + " " + points_word + "! On to the next one! Hurry!")
          alertAllPlayersButMe(player, hunt, player.user.first_name + " just found a checkpoint! Better get movin'!")
          logging.info("We are in, lets do yea and yea")
        else:
          logging.info("We had already done this thing")
      else:
        logging.info("We got a user, but the venue is not intersting for us")