Skip to content

Commit

Permalink
Rewrite the getVersion code to catch errors and catch request failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
HotaruBlaze committed Sep 10, 2023
1 parent b024535 commit ab24d94
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import re
import pickle


def getAppPath():
# Check for macOS platform and NSO-RPC freeze status
if sys.platform.startswith('darwin') and hasattr(sys, 'frozen') and sys.frozen == 'macosx_app':
Expand Down Expand Up @@ -44,6 +45,7 @@ def getAppPath():
portable_data_path = os.path.join(os.getcwd(), 'NSO-RPC_Data')
return portable_data_path if os.path.isdir(portable_data_path) else application_path


def log(info, time = time.time()):
path = getAppPath()
if not os.path.isdir(path):
Expand All @@ -58,16 +60,16 @@ def getVersion():
try:
r = requests.get('https://apps.apple.com/us/app/nintendo-switch-online/id1234806557', timeout = 10)
break
except:
log('Failed to get Apple\'s store page. Retrying...')
searchPattern = re.compile(r'Version\s*(\d\.\d\.\d)+')
version = searchPattern.findall(r.text)
if not version:
return ''
pattern = re.compile(r'(\d.\d.\d)')
if not re.search(pattern, version[0]):
return ''
return version[0]
except requests.RequestException as e:
log(f'Failed to get Apple\'s store page. Retrying... Error: {str(e)}')
else:
log('Failed to get Apple\'s store page after multiple retries.')
if r:
searchPattern = re.compile(r'Version\s*(\d\.\d\.\d)+')
version = searchPattern.search(r.text)
if version:
return version.group(1)
return ''


client_id = '71b963c1b7b6d119'
Expand Down

0 comments on commit ab24d94

Please sign in to comment.