Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions activate_this.py
Original file line number Diff line number Diff line change
@@ -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()