frozenpandaman / s3s

Successor to splatnet2statink. Takes battle data from the SplatNet 3 app and uploads it to stat.ink!
https://github.com/frozenpandaman/s3s/wiki
GNU General Public License v3.0
394 stars 72 forks source link

prefer to use NSO ver from f token gen provider #159

Closed qjzcj2008 closed 8 months ago

qjzcj2008 commented 9 months ago

The f API is always associated with the NSO version number. Mismatched NSO version sent to The f API could result in errors, just like this time.

So I think get NSO version number from Apple App Store may not the best choice, and the major f APIs provide a /config endpoint to provide the NSO version they're running. Maybe use NSO version from f APIs will be better.

It should be compatible with existing version s3s, and when get NSO version from The f APIs failed it will fallback to APP Store. #155

frozenpandaman commented 8 months ago

Thank you!! Super helpful.

frozenpandaman commented 8 months ago

I probably should have tried this out first myself...

@qjzcj2008 This uses a circular import which breaks things:

  File "/path/to/s3s/utils.py", line 10, in <module>
    SPLATNET3_URL    = iksm.SPLATNET3_URL
AttributeError: partially initialized module 'iksm' has no attribute 'SPLATNET3_URL' (most likely due to a circular import)
qjzcj2008 commented 8 months ago

sry, my bad. I just wrote a simple protype to validate my idea and ignored that import in muti modules😱

Actully, I should use delay import to avoid this. And this time I tested on my side, it should works now. This is my fix, just FYI, though you already refactor these modules to fix this.

I feel really sorry about this. I'm truly sorry.

diff --git iksm.py
 import base64, hashlib, json, os, re, sys, urllib
 import requests
 from bs4 import BeautifulSoup
-from s3s import F_GEN_URL as f_gen_url
-from s3s import A_VERSION as s3s_ver

 USE_OLD_NSOAPP_VER    = False # Change this to True if you're getting a "9403: Invalid token." error

@@ -27,9 +29,6 @@ session = requests.Session()

 def get_nsoapp_version():
        '''Fetches the current Nintendo Switch Online app version from f token genaration provider or the Apple App Store and sets it globally.'''
+       from s3s import F_GEN_URL as f_gen_url
+       from s3s import A_VERSION as s3s_ver
+       #delay import to avoid circular import

        if USE_OLD_NSOAPP_VER:
                return NSOAPP_VER_FALLBACK
frozenpandaman commented 8 months ago

@qjzcj2008 No problem, please don't worry!! More than anything, I appreciate your help and thinking to add this functionality in the first place! 😀

That's a smart idea to do it in get_nsoapp_version(), and probably works better than my solution which I just threw together in a couple of minutes. I hadn't dealt with circular imports much before so I wasn't sure the best way to solve it. And my way changed a lot more files, so maybe I should change it back in v0.6.1 😅 Then again, maybe it's better to have SPLATNET3_URL and GRAPHQL_URL defined in the same place? I guess there's some overlap between utils.py and iksm.py anyway. In the end, I don't think it matters too much, but thank you again!