There are libraries built with all of this math done for you already.
Astropy, orekit are two I recall from memory, but there are more