(client_version, client_key, client_secret, replays_dir, extract=False)
| 79 | |
| 80 | |
| 81 | def get_replay_pack(client_version, client_key, client_secret, replays_dir, extract=False): |
| 82 | try: |
| 83 | # Get OAuth token from us region |
| 84 | access_token = get_bnet_oauth_access_token("https://us.battle.net/oauth/token", client_key, client_secret) |
| 85 | |
| 86 | # Get the base url for downloading replay packs |
| 87 | download_base_url = get_base_url(access_token) |
| 88 | |
| 89 | # Get meta file infos for the give client version |
| 90 | print 'Searching replay packs with client version=' + client_version |
| 91 | meta_file_urls = search_by_client_version(access_token, client_version) |
| 92 | if len(meta_file_urls) == 0: |
| 93 | print 'No matching replay packs found for the client version!' |
| 94 | return |
| 95 | |
| 96 | # For each meta file, construct full url to download replay packs |
| 97 | print 'Building urls for downloading replay packs. num_files={0}'.format(len(meta_file_urls)) |
| 98 | download_urls=[] |
| 99 | for meta_file_url in meta_file_urls: |
| 100 | meta_file_info = get_meta_file_info(access_token, meta_file_url) |
| 101 | file_path = meta_file_info['path'] |
| 102 | download_urls.append(urlparse.urljoin(download_base_url, file_path)) |
| 103 | |
| 104 | # Download replay packs. |
| 105 | files = [] |
| 106 | for archive_url in sorted(download_urls): |
| 107 | print 'Downloading replay packs. url=' + archive_url |
| 108 | files.append(download_file(archive_url, replays_dir)) |
| 109 | |
| 110 | if extract: |
| 111 | for file in files: |
| 112 | s = '7z e {0} -o{1} -piagreetotheeula'.format(file, os.path.dirname(file)) |
| 113 | subprocess.call(s) |
| 114 | os.remove(file) |
| 115 | except Exception as e: |
| 116 | import traceback |
| 117 | print 'Failed to download replay packs. traceback={}'.format(traceback.format_exc()) |
| 118 | |
| 119 | |
| 120 | def parse_args(): |
no test coverage detected