Skip to content

Commit a6901bd

Browse files
committed
fixing boff abilities issue when wiki is unavailable
1 parent 6b07253 commit a6901bd

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class Launcher():
88

9-
version = '2025.11b160'
10-
__version__ = '2.1'
9+
version = '2026.01b110'
10+
__version__ = '2.2'
1111

1212
# holds the style of the app
1313
theme = {

src/datafunctions.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def load_cargo_cache(self, threaded_worker: ThreadObject) -> bool:
110110
if len(self.cache.starship_traits) == 0:
111111
return False
112112
self.cache.boff_abilities = get_cached_cargo_data(self, 'boff_abilities.json')
113-
if len(self.cache.boff_abilities) == 0:
113+
if len(self.cache.boff_abilities) == 0 or len(self.cache.boff_abilities.get('all', {})) == 0:
114114
return False
115115
self.cache.modifiers = get_cached_cargo_data(self, 'modifiers.json')
116116
if len(self.cache.modifiers) == 0:
@@ -945,37 +945,63 @@ def backup_cargo_data(self):
945945
copy_file(cargo_path, backups_path)
946946

947947

948-
def get_boff_data(self):
948+
def get_boff_data(self, force_offline_data: bool = False):
949949
"""
950950
Populates self.cache.boff_abilities until boff abilties are available from cargo
951+
952+
Parameters:
953+
- :param force_offline_data: Set to True to force the use of cargo backup in case the online
954+
source is unavailable
951955
"""
956+
class ThisIsTerribleError(RuntimeError):
957+
pass
958+
952959
filename = 'boff_abilities.json'
953960
filepath = os.path.join(self.config['config_subfolders']['cargo'], filename)
961+
bad_cache = False
954962

955963
# try loading from cache
956964
if os.path.exists(filepath) and os.path.isfile(filepath):
957965
last_modified = os.path.getmtime(filepath)
958966
if (datetime.now() - datetime.fromtimestamp(last_modified)).days < 7:
959967
try:
960968
self.cache.boff_abilities = load_json(filepath)
961-
self.cache.images_set |= self.cache.boff_abilities['all'].keys()
962-
return
969+
if len(self.cache.boff_abilities.get('all', {})) > 0:
970+
self.cache.images_set |= self.cache.boff_abilities['all'].keys()
971+
return
972+
else:
973+
bad_cache = True
963974
except JSONDecodeError:
964975
pass
965976

966977
# download if not exists or outdated
967978
try:
968-
auto_backup_cargo_file(self, filename)
979+
if not bad_cache:
980+
auto_backup_cargo_file(self, filename)
981+
if force_offline_data:
982+
raise ThisIsTerribleError
969983
boff_html = fetch_html(BOFF_URL)
970-
except (requests__Timeout, requests__ConnectionError):
984+
except (requests__Timeout, requests__ConnectionError, ThisIsTerribleError):
971985
backup_path = os.path.join(self.config['config_subfolders']['backups'], filename)
972986
if os.path.exists(backup_path) and os.path.isfile(backup_path):
973987
try:
974988
cargo_data = load_json(backup_path)
975989
store_json(cargo_data, filepath)
976990
self.cache.boff_abilities = cargo_data
977-
self.cache.images_set |= self.cache.boff_abilities['all'].keys()
978-
return
991+
if len(self.cache.boff_abilities.get('all', {})) > 0:
992+
self.cache.images_set |= self.cache.boff_abilities['all'].keys()
993+
return
994+
except JSONDecodeError:
995+
pass
996+
backup_path = os.path.join(self.config['config_subfolders']['auto_backups'], filename)
997+
if os.path.exists(backup_path) and os.path.isfile(backup_path):
998+
try:
999+
cargo_data = load_json(backup_path)
1000+
store_json(cargo_data, filepath)
1001+
self.cache.boff_abilities = cargo_data
1002+
if len(self.cache.boff_abilities.get('all', {})) > 0:
1003+
self.cache.images_set |= self.cache.boff_abilities['all'].keys()
1004+
return
9791005
except JSONDecodeError:
9801006
pass
9811007
sys.stderr.write(f'[Error] Html could not be retrieved ({filename})\n')
@@ -1018,4 +1044,7 @@ def get_boff_data(self):
10181044
if i == 2 and tds[rank1 + i].text.strip() in ['I', 'II']:
10191045
self.cache.boff_abilities[environment][category][i + 1][cname] \
10201046
= desc
1021-
store_json(self.cache.boff_abilities, filepath)
1047+
if len(self.cache.boff_abilities.get('all', {})) == 0:
1048+
get_boff_data(self, force_offline_data=True)
1049+
else:
1050+
store_json(self.cache.boff_abilities, filepath)

0 commit comments

Comments
 (0)