Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Showoff - A simple sports stats tracker

![Version](https://img.shields.io/badge/version-2.0.0-blue)
![Version](https://img.shields.io/badge/version-2.1.0-blue)
![Python](https://img.shields.io/badge/python-3.9+-green)
![License](https://img.shields.io/badge/license-MIT-orange)
![made with love](https://img.shields.io/badge/made%20with-%3C3-red)
Expand Down
7 changes: 6 additions & 1 deletion locales/lang_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"stats_review": "Statistics review",
"data_export": "Data export(.csv)",
"change_sport": "Change sport",
"settings": "Settings",
"about": "About",
"exit": "Exit",
"description": "Showoff is a simple sports self-statistics tracker for players or their coaches, written to be easy to use and to be informational.",
Expand All @@ -51,5 +52,9 @@
"per_game": "PER-GAME",
"value": "VALUE",
"change_lang": "Change language",
"unsupported_version": "Unsupported save version\nFor more information, see the readme"
"unsupported_version": "Unsupported save version\nFor more information, see the readme",
"changed_sport": "Sport changed to",
"back": "Back",
"name": "Name",
"date": "Date"
}
7 changes: 6 additions & 1 deletion locales/lang_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"stats_review": "Статистика",
"data_export": "Экспорт данных(.csv)",
"change_sport": "Поменять спорт",
"settings": "Настройки",
"about": "О приложении",
"exit": "Выход",
"description": "Showoff это простой трекер статистики для спорта, написанный чтобы быть легким и информациональным.",
Expand All @@ -51,5 +52,9 @@
"per_game": "ЗА-ИГРУ",
"value": "ЗНАЧ",
"change_lang": "Смена языка",
"unsupported_version": "Неподдерживаемая версия сохранения\nДля большей информации, смотрите README.md"
"unsupported_version": "Неподдерживаемая версия сохранения\nДля большей информации, смотрите README.md",
"changed_sport": "Спорт изменен на",
"back": "Назад",
"name": "Имя",
"date": "Дата"
}
2 changes: 1 addition & 1 deletion source/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = '2.0.0'
VERSION = '2.1.0'
LOGO = """
███████╗██╗ ██╗ ██████╗ ██╗ ██╗ ██████╗ ███████╗███████╗
██╔════╝██║ ██║██╔═══██╗██║ ██║██╔═══██╗██╔════╝██╔════╝
Expand Down
40 changes: 37 additions & 3 deletions source/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,35 @@
from ui_handler import texts
from __init__ import VERSION

sport = 0

try:
with open('preferences.json', 'r', encoding='utf-8') as f:
preferences = json.load(f)
if preferences['sport'] == 1:
sport = 1
elif preferences['sport'] == 2:
sport = 2
else:
pass
except KeyError:
pass

while True:
try:
sport = int(input(f'''
if sport != 1 and sport != 2:
sport = int(input(f'''
{texts["select_sport"]}:
[1] - {texts["basketball"]}
[2] - {texts["soccer"]}
>>>'''))
if sport > 2 or sport < 1:
print("Invalid option")
if sport > 2 or sport < 1:
print("Invalid option")
else:
with open('preferences.json', 'w', encoding='utf-8') as f:
preferences['sport'] = sport
json.dump(preferences, f, ensure_ascii=False, indent=4)
break
else:
break
except ValueError:
Expand Down Expand Up @@ -65,6 +85,17 @@
sys.exit(1)


def change_sport(preferences):
with open('preferences.json', 'w', encoding='utf-8') as f:
if preferences['sport'] == 1:
preferences['sport'] = 2
json.dump(preferences, f, ensure_ascii=False, indent=4)
print(f'{texts["changed_sport"]} {texts["soccer"]}')
else:
preferences['sport'] = 1
json.dump(preferences, f, ensure_ascii=False, indent=4)
print(f'{texts["changed_sport"]} {texts["basketball"]}')

def add_match():
if sport == 1:
while True:
Expand Down Expand Up @@ -134,6 +165,9 @@ def add_match():


def save():
if db['version'] != VERSION:
db['version'] = VERSION

if sport == 1:
try:
with open('basketball.json', 'w', encoding='utf-8') as f:
Expand Down
25 changes: 19 additions & 6 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
games = data_handler.db["games"]
export = export_handler
texts = ui.texts
preferences = data_handler.preferences

if db.sport == 1:
sport = 'basketball'
Expand All @@ -36,8 +37,10 @@ def main():
Menu.show_info(False)
print(f"{texts["currently_in"]} {sport}")
user_choice = Menu.create_menu()

if user_choice == 1:
if user_choice == ValueError:
Menu.clear_screen()
pass
elif user_choice == 1:
db.add_match()
print(f"{texts["added"]}")
db.save()
Expand Down Expand Up @@ -77,7 +80,20 @@ def main():
Menu.clear_screen()

elif user_choice == 5:
os.execl(sys.executable, sys.executable, *sys.argv)
print(f'{texts["settings"]}:')
choice = Menu.settings_menu()
if choice == 1:
ui_handler.change_lang(preferences, ui_handler.lang)
db.save()
os.execl(sys.executable, sys.executable, *sys.argv)
elif choice == 2:
db.change_sport(preferences)
db.save()
os.execl(sys.executable, sys.executable, *sys.argv)
elif choice == 3:
pass
elif choice == ValueError:
pass

elif user_choice == 6:
Menu.clear_screen()
Expand All @@ -86,9 +102,6 @@ def main():
Menu.clear_screen()

elif user_choice == 7:
os.execl(sys.executable, sys.executable, *sys.argv)

elif user_choice == 8:
break


Expand Down
3 changes: 3 additions & 0 deletions source/statistics_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def calculate_efficiency(points, rebounds, assists, steals, blocks, missed, miss


def show_stats(match_index):
print(f'{texts["name"]}: {games[match_index]["name"]}')
print(f'{texts["date"]}: {games[match_index]["date"]}')
print("─" * 35)
if sport == 1:
table = [["Points", str(games[match_index]["points"])], ["Minutes", str(games[match_index]["minutes"])],
["2 Pointers", f'{str(games[match_index]["2pt_shots_made"])}/{str(games[match_index]["2pt_attempts"])}'], ["3 Pointers", f'{str(games[match_index]["3pt_shots_made"])}/{str(games[match_index]["3pt_attempts"])}'],
Expand Down
80 changes: 57 additions & 23 deletions source/ui_handler.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import os
import json
import sys

from __init__ import INFO

while True:
try:
lang = int(input("[1] - English\n[2] - Русский\n>>>"))
if lang == 1:
lang = 'en'
break
elif lang == 2:
lang = 'ru'
break
else:
print("Out of range.")

except ValueError:
print('Invalid choice')

except Exception as e:
print(f'ERROR: {e}')
input('Press Enter to exit...')
sys.exit(1)
with open('preferences.json', 'r', encoding='utf-8') as f:
preferences = json.load(f)
lang = preferences['lang']
break
except FileNotFoundError:
with open('preferences.json', 'w', encoding='utf-8') as f:
lang = int(input("[1] - English\n[2] - Русский\n>>>"))
if lang == 1:
lang = 'en'
json.dump({"lang": lang}, f, ensure_ascii=False, indent=4)
break
elif lang == 2:
lang = 'ru'
json.dump({"lang": lang}, f, ensure_ascii=False, indent=4)
break
else:
print("Out of range.")


with open(f'locales/lang_{lang}.json', 'r', encoding='utf-8') as f:
Expand All @@ -33,22 +32,45 @@
[2] - {texts["view_games"]}
[3] - {texts["stats_review"]}
[4] - {texts["data_export"]}
[5] - {texts["change_sport"]}
[5] - {texts["settings"]}
[6] - {texts["about"]}
[7] - {texts["change_lang"]}
[8] - {texts["exit"]}
[7] - {texts["exit"]}
"""

SETTINGS_MENU = f"""
[1] - {texts["change_lang"]}
[2] - {texts["change_sport"]}
[3] - {texts["back"]}
"""

DESCRIPTION = f"{texts["description"]}\nhttps://github.com/worthyworm/showoff"

def change_lang(preferences, lang):
with open('preferences.json', 'w', encoding='utf-8') as f:
if lang == 'en':
preferences['lang'] = 'ru'
json.dump(preferences, f, ensure_ascii=False, indent=4)
print("Язык изменен на русский.")
input("Enter чтобы продолжить...")
elif lang == 'ru':
preferences['lang'] = 'en'
json.dump(preferences, f, ensure_ascii=False, indent=4)
print("Language set to English.")
input("Enter to continue...")

class Menu:

@staticmethod
def create_menu():
print(MENU)
choice = int(input(f"{texts["select"]} >> "))
return choice
try:
choice = int(input(f"{texts["select"]} >> "))
return choice
except ValueError:
choice = ValueError
return choice
except Exception as e:
print(f'ERROR: {e}')

@staticmethod
def show_info(full):
Expand All @@ -60,3 +82,15 @@ def show_info(full):
@staticmethod
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')

@staticmethod
def settings_menu():
try:
print(SETTINGS_MENU)
choice = int(input(f"{texts["select"]} >> "))
return choice
except ValueError:
choice = ValueError
return choice
except Exception as e:
print(f'ERROR: {e}')