# Path: whyattend/replays.py
# def parse_replay(replay_blob):
# def players_list(replay_json, team):
# def player_won(replay_json):
# def get_own_team(replay_json):
# def player_team(replay_json):
# def is_stronghold(replay_json):
# def is_cw(replay_json):
# def guess_clan(replay_json):
# def guess_enemy_clan(replay_json):
# def score(replay_json):
# def resources_earned(json_second, player_id):
# def player_performance(json_second, vehicles, players):


import os, hashlib, urllib2, json, sys
from whyattend import replays
"""
    Script that goes through all .wotreplay files in a folder
    and tries to find CW replays that were not uploaded to the tracker yet
    by comparing the list of players, enemy clan and map name.
"""


sys.path += ['.', '..']


TRACKER_URL = sys.argv[1]

if __name__ == '__main__':
    checksums = json.load(urllib2.urlopen(TRACKER_URL + '/api/battle-checksums'))['hashes']

    for root, subfolders, files in os.walk(sys.argv[2]):
        for file in files:
            if not file.endswith('.wotreplay'): continue
            try:
                replay_blob = open(os.path.join(root, file), 'rb').read()

# Path: whyattend/replays.py
# def parse_replay(replay_blob):
# def players_list(replay_json, team):
# def player_won(replay_json):
# def get_own_team(replay_json):
# def player_team(replay_json):
# def is_stronghold(replay_json):
# def is_cw(replay_json):
# def guess_clan(replay_json):
# def guess_enemy_clan(replay_json):
# def score(replay_json):
# def resources_earned(json_second, player_id):
# def player_performance(json_second, vehicles, players):


# Path: scripts/find_cw_replays.py
import os, hashlib, urllib2, json, sys
from whyattend import replays

"""
    Script that goes through all .wotreplay files in a folder
    and tries to find CW replays that were not uploaded to the tracker yet
    by comparing the list of players, enemy clan and map name.
"""


sys.path += ['.', '..']


TRACKER_URL = sys.argv[1]

if __name__ == '__main__':
    checksums = json.load(urllib2.urlopen(TRACKER_URL + '/api/battle-checksums'))['hashes']

    for root, subfolders, files in os.walk(sys.argv[2]):
        for file in files:
            if not file.endswith('.wotreplay'): continue
            try:
                replay_blob = open(os.path.join(root, file), 'rb').read()

                replay = replays.parse_replay(replay_blob)