Assignment 6

Author

Stephen Klayer

NASA

The following code will extract certain points of latitude and longitude from NASA’s site. These coordinates can be mapped in accordance with Earth so people can map where the ISS is orbiting at a certain time.

Load in Libraries

library(tidyverse) 
library(jsonlite)  
library(magrittr)  
library(httr)

Obtain the API

url <- "http://api.open-notify.org/iss-now.json"

url_obtain <-
  url %>% 
  GET()

Fetch the data from NASA

url_fetch <- 
  url_obtain %>% 
  content(as = "text",
          encoding = "UTF-8") %>% 
  fromJSON() %>% 
  use_series(iss_position)

Combine above ideas into a function to extract the data into a data frame. Includes coordinates and timestamp

NASA_extract <- function() {
  
url <- "http://api.open-notify.org/iss-now.json"


url_obtain <- 
  url %>% 
  GET() %>% 
  content(as = "text",encoding = "UTF-8") %>% 
  fromJSON()


latitude <- 
    url_obtain %>% 
    use_series(iss_position) %>% 
    use_series(latitude)
  
longitude <- 
    url_obtain %>% 
    use_series(iss_position) %>% 
    use_series(longitude)

timestamp <-
  url_obtain %>% 
  use_series(timestamp)

NASA_data <- data.frame(latitude,longitude, timestamp)

return(NASA_data)
}

Extract 20 versions of longitude and latitude to find the movement

several <- function(times) {
  
  NASA_data <- data.frame()
  
  for (i in 1:times){
    
  NASA_data <- bind_rows(NASA_data, NASA_extract())
  print((i/times))
  
    Sys.sleep(1)
  }

return(NASA_data)    
}

extractedData <- several(20)
[1] 0.05
[1] 0.1
[1] 0.15
[1] 0.2
[1] 0.25
[1] 0.3
[1] 0.35
[1] 0.4
[1] 0.45
[1] 0.5
[1] 0.55
[1] 0.6
[1] 0.65
[1] 0.7
[1] 0.75
[1] 0.8
[1] 0.85
[1] 0.9
[1] 0.95
[1] 1