feba66 / spacetraders-sdk-v2

Total rewrite to use no generated code
GNU General Public License v2.0
1 stars 1 forks source link

Orbit returns KeyError if Get_Ships() has not been called #1

Open ipaulo opened 1 year ago

ipaulo commented 1 year ago

I eventually figured out st.Get_Ships() would fix this. Not sure if this is a bug or the result of a perfectly OK design pattern that I just didn't understand.

st = SpaceTraders()
st.Login(os.getenv("TOKEN"))

miners = ['LEELOO-1', 'LEELOO-2']
for s in miners:
    st.Orbit(s)
2023-05-21 22:08:17,517 - 42884 - SpaceTraders-42884 - INFO - GET https://api.spacetraders.io/v2/ 200
2023-05-21 22:08:17,627 - 42884 - SpaceTraders-42884 - INFO - POST https://api.spacetraders.io/v2/my/ships/LEELOO-1/orbit 200
Traceback (most recent call last):
  File "c:\code\geba\traders.py", line 99, in <module>
    mine(miners=miningships)
  File "c:\code\geba\traders.py", line 76, in mine
    st.Orbit(s)
  File "c:\code\geba\api.py", line 935, in Orbit
    return self.ships[shipSymbol].nav
           ~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'LEELOO-1'
feba66 commented 1 year ago

jup i did not add the "if shipsymbol in self.ships" to every method