The Javascript code below is running on the client device. It polls the ISS API every 1.5 seconds, converting the returned latitude and longitude into a mercator projection. Further code uses the P5 library to display the graphics on the webpage. All code can be viewed on my Github.
complete: function (data) {
if (data.readyState === 4 && data.status === 200) {
Lat = data.responseJSON.latitude;
Long = data.responseJSON.longitude;
Velocity = data.responseJSON.velocity.toFixed(2).toString();
Altitude = data.responseJSON.altitude.toFixed(2).toString();
var x = (parseFloat(Long) + 180) * (MapWidth / 360);
var latRad = (parseFloat(Lat) * Math.PI / 180);
var mercN = (Math.log(Math.tan((Math.PI / 4) + (latRad / 2))));
var y = (MapHeight / 2) - (MapWidth * mercN / (2 * Math.PI));
The Python code below sends an email if the latitude and longitude values are within a certain range. The "findISS" function works in a very similar way to the javascript implementation above. I run the code continuously on a Raspberry Pi.
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
while True:
data = findISS()
sleep(0.5)
if (Latmin < float(data['iss_position']['latitude']) < Latmax) and (Longmin < float(data['iss_position']['latitude']) < Longmax):
mmessage = """\
Subject: ISS Tracker
ISS overhead"""
server.sendmail(sender_email, receiver_email, message)
sleep(20)