From b0aebb575204dc618aa26e188b7baaa714ab3d56 Mon Sep 17 00:00:00 2001 From: Nemor38 <140786267+Nemor38@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:07:37 +0100 Subject: [PATCH] Create activate_this.py --- activate_this.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 activate_this.py diff --git a/activate_this.py b/activate_this.py new file mode 100644 index 0000000..7f32375 --- /dev/null +++ b/activate_this.py @@ -0,0 +1,33 @@ +import requests +import csv +import time + +def fetch_iss_location(): + url = "http://api.open-notify.org/iss-now.json" + response = requests.get(url) + data = response.json() + timestamp = data['timestamp'] + latitude = data['iss_position']['latitude'] + longitude = data['iss_position']['longitude'] + return timestamp, latitude, longitude + +def write_to_csv(filename, data): + with open(filename, 'a', newline='') as file: + writer = csv.writer(file, delimiter=';') + writer.writerow(data) + +def main(): + filename = 'iss_location.csv' + headers = ['Timestamp', 'Latitude', 'Longitude'] + with open(filename, 'w', newline='') as file: + writer = csv.writer(file, delimiter=';') + writer.writerow(headers) + while True: + timestamp, latitude, longitude = fetch_iss_location() + data = [timestamp, latitude, longitude] + write_to_csv(filename, data) + print("Data recorded to CSV") + time.sleep(5) + +if __name__ == "__main__": + main()