Exemplo n.º 1
0
 def post(self):
     user = UserFromSession(get_current_session()).get_user()
     game = Game(userX = user,
                 moveX = True,
                 last_cell = -1,
                 all_mini_wins = [' ']*9,
                 metaboard = ['         ']*9)
     game.put()
     self.redirect('/game?g=' + str(game.key().id()))
Exemplo n.º 2
0
def get_todays_games():

	games_db = session.query(Game).filter(Game.date == datetime.date.today()).all()

	while games_db == []:
	
		browser.visit(url)
		content = browser.html
		soup = BeautifulSoup(content, 'lxml')

		games = soup.findAll('article', {'class':'scoreboard'})

		for i in range(len(games)):
			away = games[i].find('tr', {'class': 'away'}).find('span', {'class': 'sb-team-short'})
			home = games[i].find('tr', {'class': 'home'}).find('span', {'class': 'sb-team-short'})
			time = games[i].find('span', {'class': 'time'})
			print ("{}@{} {}".format(away.text, home.text, time.text))
			new_game = Game(date=datetime.date.today(), time=time.text, away_team=away.text, home_team=home.text)
			session.add(new_game)
				
		session.commit()
		session.close()
		
		games_db = session.query(Game).filter(Game.date == datetime.date.today()).all()
	return games_db
Exemplo n.º 3
0
    def post(self):
        if not self.user:
            logging.critical('Invalid vote attempt detected!')
        else:
            game_id = self.request.get('game_id')
            game = Game.get_by_key_name(game_id)
            #game = retrieveCache(game_id, Game)
            if (self.user.user_id in game.users) and game.can_vote:
                if self.user.user_id in game.users_voted:
                    game = removeVote(game, self.user)
                resetAFK(self.user)
                choice = int(self.request.get('part_voted'))
                if str(self.user.user_id) == game.users_next_parts[choice]:
                    logging.critical('Attempt to vote for self detected. user_id: ' + str(self.user.user_id))
                game.users_voted.append(self.user.user_id)
                game.votes.append(choice)
                if allUsersVoted(game):
                    changeToDisplayPhase(game)
                else:
                    game.put()
                    #storeCache(game, game_id)
                self.response.headers.add_header('response', "s")
                return

        self.response.headers.add_header('response', "n")
        return
Exemplo n.º 4
0
    def post(self):
        if not self.user:
            logging.critical('Invalid end-text attempt detected!')
        else:
            game_id = self.request.get('game_id')
            game = Game.get_by_key_name(game_id)
            response = {}
            response['end_text'] = getEndText(game)
            self.response.out.write(json.dumps(response))

        return
Exemplo n.º 5
0
def main():
    url = 'https://aoe2.net/api/matches'
    data = requests.get(url, params={'game':'aoe2de', 'count':10, 'since':1620693540})
    myArray = json.loads(data.text)
    games = []
    for game in myArray:
        print(game)
        myGame = Game(game)
        print(myGame)
        games.append(myGame)
    return games
Exemplo n.º 6
0
def removeUser(game_id, user_id):
    game = Game.get_by_key_name(game_id)
    user = retrieveCache(user_id, User)
    user.current_game = None
    game.users.remove(str(user_id))
    game.current_players -= 1
    storeCache(user, user_id)
    try:
        game.put()
        #storeCache(game, str(game.game_id))
    except Exception, ex:
        logging.critical(ex)
Exemplo n.º 7
0
    def post(self):
        if not self.user:
            logging.critical('Invalid choice fetching detected!')
        else:
            info = json.loads(self.request.body)
            game_id = str(info['game_id'])
            game = Game.get_by_key_name(game_id)
            #game = retrieveCache(game_id, Game)
            game = checkForDoubleSubmissions(game)
            json_string = json.dumps({"choices": game.next_parts})
            self.response.out.write(json_string);

        return
Exemplo n.º 8
0
def findGame(user, length):
    query = Game.gql("WHERE current_players <:1 AND game_length =:2 ORDER BY current_players ASC", MAX_PLAYERS, length)
    results = query.fetch(None)
    if len(results) == 0:
        return None

    for result in results:
        game_id = joinGame(user, result.game_id)
        if game_id is False:
            continue
        else:
            return result.game_id

    return None
Exemplo n.º 9
0
    def get(self):
        if not self.user:
            self.render(u'login_screen')
        else:
            game_id = self.request.get('game_id')
            game = Game.get_by_key_name(game_id)
            #game = retrieveCache(game_id, Game)
            if not self.user.user_id in game.users:
                self.render(u'error_screen')
            elif len(game.users) > 1:
                startGame(game_id)
                self.redirect("/game_screen?" + urllib.urlencode({'game_id':game_id}))

        return
Exemplo n.º 10
0
 def get(self):
     game_id = self.request.get('game_id')
     if game_id is None:
         info = json.loads(self.request.body)
         game_id = info['game_id']
     game = Game.get_by_key_name(str(game_id))
     #game = retrieveCache(str(game_id), Game)
     self.response.headers['Content-type'] = 'text/html'
     if not self.user:
         self.render(u'login_screen')
     else:
         names, pictures = getUserInfo(game_id)
         self.render(u'game_screen', game_id=game_id, user_id=self.user.user_id, end_sentence=game.end_sentence, start_sentence=game.start_sentence, zipList=zip(names,pictures))
     return
Exemplo n.º 11
0
    def post(self):
        if not self.user:
            logging.critical("Invalid part submission detected!")
        else:
            info = json.loads(self.request.body)
            game_id = info['game_id']
            game = Game.get_by_key_name(str(game_id))
            #game = retrieveCache(str(game_id), Game)
            if self.user.user_id in game.users and not self.user.user_id in game.users_next_parts and game.can_submit:
                next_part = info['next_part']
		next_part = cleanSubmission(next_part)
                game = Game.get_by_key_name(str(game_id))
                #game = retrieveCache(str(game_id), Game)
                game.next_parts.append(next_part)
                game.users_next_parts.append(self.user.user_id)
                game.put()
                time_left = abs((datetime.datetime.now() - game.end_submission_time).seconds) 
                if allUsersSubmitted(game) and time_left > 10:
                    changeToVotingPhase(game)
                self.response.headers.add_header('success', 's')
            else:
                self.response.headers.add_header('success', 'f')
        return
Exemplo n.º 12
0
 def post(self):
     if self.user:
         info = json.loads(self.request.body)
         game_id = info['game_id']
         user = self.user
         try:
             game = Game.get_by_key_name(game_id)
             #game = retrieveCache(game_id, Game)
             db.delete(game)
             #deleteData(game, game_id)
             user = resetPlayerHost(user.user_id)
             self.user.current_game = None
             storeCache(user, user.user_id)
         except Exception, ex:
             logging.critical(ex)
Exemplo n.º 13
0
 def get(self):
     if not self.user:
         self.render(u'login_screen')
     else:
         if self.user.first_time:
             self.user.first_time = False
             storeCache(self.user, self.user.user_id)
             self.render(u'user_settings')
         else:
             in_game = False
             if not self.user.current_game is None:
                 game = Game.get_by_key_name(str(self.user.current_game))
                 if not game is None:
                     in_game = game.started 
             self.render(u'menu_screen', in_game=in_game, game_id=self.user.current_game)
Exemplo n.º 14
0
def joinGame(user, game_id):
    result = Game.get_by_key_name(str(game_id))
    #result = retrieveCache(str(game_id), Game)
    if result.current_players == MAX_PLAYERS or result.started or (str(user.user_id) in result.users):
        return False
    result.users.append(user.user_id)
    result.current_players += 1
    resetAFK(user)
    user.current_game = str(game_id)
    storeCache(user, user.user_id)
    if result.current_players == MAX_PLAYERS:
        startGame(game_id)
        #storeCache(result, str(game_id))
        return result.game_id
    result.put()
    #storeCache(result, str(game_id))
    return result.game_id
Exemplo n.º 15
0
def startGame(game_id):
    game = Game.get_by_key_name(str(game_id))
    #game = retrieveCache(str(game_id), Game)
    if game.started:
        return False

    game.started = True
    current_time = datetime.datetime.now()
    end_submission = current_time + datetime.timedelta(seconds=SUBMISSION_TIME)
    game.end_submission_time = end_submission
    game.can_submit = True
    game.next_parts = []
    game.users_next_parts = []
    for user in game.users:
        game.scores.append(0)
    game.put()
    #storeCache(game, str(game_id))
    return True
 def post(self):
     if not self.user:
         logging.critical("Invalid vote completion verification detected!")
     else:
         game_id = self.request.get('game_id')
         game = Game.get_by_key_name(game_id)
         #game = retrieveCache(game_id, Game)
         self.response.headers['Content-type'] = 'application/json'
         if not game.can_vote and game.display_phase:
             self.response.headers.add_header('completed', "v")
             recent_winner_string = "\"" + game.winning_sentences[len(game.winning_sentences)-1] + "\" By: " + game.winning_users_names[len(game.winning_users_names) - 1]
             self.response.headers.add_header('recent_winner', recent_winner_string)
         elif datetime.datetime.now() > game.end_vote_time:
             markAFKS(game, game.users_voted)
             changeToDisplayPhase(game, self)
         else:
             self.response.headers.add_header('completed', "i")
         response = {}
         response['winning_data'] = getRecentScoreInfo(game)
         self.response.out.write(json.dumps(response))
     return
 def post(self):
     if not self.user:
         logging.critical("Invalid display completion verification detected!")
         return
     else:
         game_id = self.request.get('game_id')
         game = Game.get_by_key_name(game_id)
         #game = retrieveCache(game_id, Game)
         response = {}
         self.response.headers['Content-type'] = 'application/json'
         response['updated_story'] = getStoryStringForGameScreen(game)
         response['scores'] = getScoreInfo(game)
         response['profiles'], response['afks'] = getProfilesAndAFKS(response['scores'])
         self.response.out.write(json.dumps(response))
         if (game.num_phases < game.game_length or game.went_to_submission):
             if not game.display_phase and game.can_submit:
                 self.response.headers.add_header('response', "v")
                 return
             elif datetime.datetime.now() > game.end_display_time:
                 changeToSubmissionPhase(game, self)
                 game.went_to_submission = True
                 game.put()
                 #storeCache(game, game_id)
                 return
             self.response.headers.add_header('response', "i")
             self.response.headers.add_header('updated_story', "")
         else:
             if (not game.display_phase) and game.finished:
                 self.response.headers.add_header('response', "v")
                 return
             elif datetime.datetime.now() > game.end_display_time:
                 self.response.headers.add_header('response', "v")
                 finishGame(game)
                 return
             self.response.headers.add_header('response', "i")
     return
Exemplo n.º 18
0
 def __init__(self, request):
     game_id = request.get('g') # The client passes the game key back in order to open up the channel
     if game_id:
         self.game = Game.get_by_id(int(game_id))
Exemplo n.º 19
0
def initializeGame(game_id, max_players, start_sentence, end_sentence, length):
    game_id = getNextGameID()
    newGame = Game(key_name=str(game_id))
    newGame.game_id = game_id
    newGame.created = datetime.datetime.now()
    newGame.can_vote = False
    newGame.story = []
    newGame.users = []
    newGame.current_players = 0
    newGame.num_phases = 1
    #newGame.num_phases = 9
    newGame.end_sentence = end_sentence
    newGame.start_sentence = start_sentence
    newGame.can_submit = False
    newGame.display_phase = False
    newGame.finished = False
    newGame.started = False
    newGame.users = []
    newGame.game_length = length
    newGame.put()
    #storeCache(newGame, str(game_id))
    return game_id
Exemplo n.º 20
0
 def get(self):
     query = Game.all()
     games = query.fetch(None)
     cleanupProcess(games)
     return
Exemplo n.º 21
0
 def post(self):
     game_id = self.request.get('game_id')
     game = Game.get_by_key_name(game_id)
     postToReddit(game)
     removeGame(game)
Exemplo n.º 22
0
def getLobbyGames():
    query = Game.gql("WHERE current_players <:1 AND started =:2 ORDER BY current_players DESC", MAX_PLAYERS, False)
    return query.fetch(1000000)