Created
April 11, 2020 10:32
-
-
Save probablytom/3a95c2233d4ad7949d2b5989472e5b81 to your computer and use it in GitHub Desktop.
Attempt #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route("/dereferences") | |
@app.route("/dereferences/<format>") | |
def new_fix_dereferences(format="json"): | |
bad_games = [] | |
checked = [] | |
for player in players.find({'Username': {'$exists': True}}): | |
for game_id in player['Games']: | |
if game_id != 'none' and game_id != 'waiting' and game_id not in checked: | |
# print('checking ' + str(game_id)) | |
checked.append(game_id) | |
game = games.find_one({'_id': game_id}) | |
if game is None: | |
try: | |
while True: exec(input(' :: ')) | |
except: | |
pass | |
# Check in opp's game list | |
try: | |
opp_id = game['p1'] if game['p2'] == player['_id'] else game['p2'] | |
opp = players.find_one({'_id': opp_id}) | |
opp_has_game = game_id in opp['Games'] | |
except Exception as e: | |
print(e) | |
raise e | |
# Check seen_by_one | |
seen_by_one = 'seen_by_one' in game.keys() | |
# Check abandon endpoint | |
abandoned = game.get('p1_abandon', False) or game.get('p2_abandon', False) or 'apply abandon penalty' in game['most recent activity'] | |
# Overall | |
is_valid_game = opp_has_game or seen_by_one or abandoned | |
if not is_valid_game: | |
print(game_id, player['Username'], opp['Username'], {'seen?': seen_by_one, 'abandoned?': abandoned, 'missing?': opp_has_game}) | |
bad_games.append(game) | |
return dumps({'bad_games': bad_games}), 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment