First release, add more command line arguments, compile binary, add pyinstaller and building assets

This commit is contained in:
Ahrimdon 2023-10-08 07:23:27 -04:00
parent a2accbf56b
commit 2d52212b3f
21 changed files with 41 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

BIN
assets/build/icon/16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/build/icon/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
assets/build/icon/48x48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
assets/build/icon/64x64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
assets/build/icon/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

BIN
bin/get_cod_stats.exe Normal file

Binary file not shown.

10
build.bat Normal file
View File

@ -0,0 +1,10 @@
@echo off
cd /d %~dp0 :: Change directory to the location of this batch file
call venv\Scripts\activate :: Activate the virtual environment
pyinstaller --noconfirm --onefile --console --icon "assets\build\icon\icon.ico" get_cod_stats.py --distpath="bin" -n "get_cod_stats"
rmdir /s /q build
del /q "get_cod_stats.spec"
pause

Binary file not shown.

Binary file not shown.

BIN
deps/packaging-23.2-py3-none-any.whl vendored Normal file

Binary file not shown.

BIN
deps/pefile-2023.2.7-py3-none-any.whl vendored Normal file

Binary file not shown.

BIN
deps/pip-23.2.1-py3-none-any.whl vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
deps/zipp-3.17.0-py3-none-any.whl vendored Normal file

Binary file not shown.

View File

@ -2,6 +2,11 @@ import json
import os
import argparse
from cod_api import API, platforms
import asyncio
# Prevent Async error from showing
if os.name == 'nt':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
replacements = {
# Gamemodes
@ -247,7 +252,12 @@ replacements = {
api = API()
COOKIE_FILE = 'cookie.txt'
def get_and_save_data():
def get_and_save_data(player_name=None):
# Create the stats directory if it doesn't exist
DIR_NAME = 'stats'
if not os.path.exists(DIR_NAME):
os.makedirs(DIR_NAME)
# Check if cookie file exists
if os.path.exists(COOKIE_FILE):
with open(COOKIE_FILE, 'r') as f:
@ -257,8 +267,9 @@ def get_and_save_data():
with open(COOKIE_FILE, 'w') as f:
f.write(api_key)
# Get player name from user
player_name = input("Please enter the player's username (with #1234567): ")
# If player_name is not provided via command line, get it from user input
if not player_name:
player_name = input("Please enter the player's username (with #1234567): ")
# Login with sso token
api.login(api_key)
@ -270,16 +281,16 @@ def get_and_save_data():
map_list = api.ModernWarfare.mapList(platforms.Activision)
identities = api.Me.loggedInIdentities()
# Save results to a JSON file
with open('stats.json', 'w') as json_file:
# Save results to a JSON file inside the stats directory
with open(os.path.join(DIR_NAME, 'stats.json'), 'w') as json_file:
json.dump(player_stats, json_file, indent=4)
with open('match_info.json', 'w') as json_file:
with open(os.path.join(DIR_NAME, 'match_info.json'), 'w') as json_file:
json.dump(match_info, json_file, indent=4)
with open('season_loot.json', 'w') as json_file:
with open(os.path.join(DIR_NAME, 'season_loot.json'), 'w') as json_file:
json.dump(season_loot, json_file, indent=4)
with open('map_list.json', 'w') as json_file:
with open(os.path.join(DIR_NAME, 'map_list.json'), 'w') as json_file:
json.dump(map_list, json_file, indent=4)
with open('identities.json', 'w') as json_file:
with open(os.path.join(DIR_NAME, 'identities.json'), 'w') as json_file:
json.dump(identities, json_file, indent=4)
def recursive_key_replace(obj, replacements):
@ -354,6 +365,7 @@ def main():
# Add arguments for your commands
parser.add_argument("--replace-data", action="store_true", help="Beautify the data in stats.json")
parser.add_argument("--replace-match-data", action="store_true", help="Beautify the match data in match_info.json")
parser.add_argument("--player-name", type=str, help="Player's username (with #1234567)")
args = parser.parse_args()
@ -362,7 +374,7 @@ def main():
elif args.replace_match_data:
beautify_match_data()
else:
get_and_save_data()
get_and_save_data(args.player_name)
if __name__ == "__main__":
main()
main()

View File

@ -15,7 +15,7 @@ def create_venv():
f.write("venv\\Scripts\\activate")
def upgrade_pip():
subprocess.check_call([os.path.join('venv', 'Scripts', 'python'), '-m', 'pip', 'install', '--upgrade', 'pip'])
subprocess.check_call([os.path.join('venv', 'Scripts', 'pip'), 'install', '--no-index', '--find-links=deps', 'pip'])
def install_wheel():
subprocess.check_call([os.path.join('venv', 'Scripts', 'pip'), 'install', '--no-index', '--find-links=deps', 'wheel'])
@ -23,7 +23,11 @@ def install_wheel():
def install_requirements_in_venv():
# Use the full path to the wheel file
wheel_path = os.path.join('src', 'cod_api-2.0.1-py3-none-any.whl')
subprocess.check_call([os.path.join('venv', 'Scripts', 'pip'), 'install', '--no-index', '--find-links=deps', wheel_path])
subprocess.check_call([os.path.join('venv', 'Scripts', 'pip'), 'install', '--no-index', '--find-links=deps', wheel_path])
def install_build_dependencies():
subprocess.check_call([os.path.join('venv', 'Scripts', 'pip'), 'install', '--no-index', '--find-links=deps', 'pyinstaller'])
subprocess.check_call([os.path.join('venv', 'Scripts', 'pip'), 'uninstall', 'enum34', '-y'])
if __name__ == "__main__":
if not deps_exists():
@ -38,4 +42,6 @@ if __name__ == "__main__":
install_wheel()
print("Installing packages in the virtual environment...")
install_requirements_in_venv() # Call the function to install the requirements
print("Installing build dependencies...")
install_build_dependencies()
print("Setup complete.")