diff --git a/ch10/earth.gif b/ch10/earth.gif new file mode 100644 index 0000000..899fd76 Binary files /dev/null and b/ch10/earth.gif differ diff --git a/ch10/iss.gif b/ch10/iss.gif new file mode 100644 index 0000000..5648de8 Binary files /dev/null and b/ch10/iss.gif differ diff --git a/ch10/iss.py b/ch10/iss.py new file mode 100644 index 0000000..f75bbd3 --- /dev/null +++ b/ch10/iss.py @@ -0,0 +1,49 @@ +import requests, json, turtle + +iss = turtle.Turtle() + +def setup(window): + global iss + + window.setup(1000, 500) + window.bgpic('earth.gif') + window.setworldcoordinates(-180, -90, 180, 90) + turtle.register_shape('iss.gif') + iss.shape('iss.gif') + +def mov_iss(lat, long): + global iss + + iss.penup() + iss.goto(lat, long) + iss.pendown() + +def track_iss(): + url = 'http://api.open-notify.org/iss-now.json' + + response = requests.get(url) + + if (response.status_code == 200): + response_dictionary = json.loads(response.text) + position = response_dictionary['iss_position'] + # print('Координаты МКС: ', position['longitude'] + ',' + position['latitude']) + lat = float(position['latitude']) + long = float(position['longitude']) + mov_iss(lat, long) + else: + print('Хьюстон, у нас проблема:', response.status_code) + widget = turtle.getcanvas() + widget.after(5000, track_iss()) + + +def main(): + global iss + + screen = turtle.Screen() + setup(screen) + track_iss() + + +if __name__ == '__main__': + main() + turtle.mainloop()