diff --git a/Project.toml b/Project.toml index 0efaf103..5c3ec794 100644 --- a/Project.toml +++ b/Project.toml @@ -19,6 +19,7 @@ Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PlanetaryEphemeris = "d83715d0-7e5f-11e9-1a59-4137b20d8363" @@ -44,6 +45,7 @@ Interpolations = "0.14" IntervalArithmetic = "0.20" IntervalRootFinding = "0.5.11" JLD2 = "0.4" +JSON = "0.21" PlanetaryEphemeris = "0.7" Quadmath = "0.5" SPICE = "0.2" diff --git a/src/NEOs.jl b/src/NEOs.jl index eeab461c..cffa8832 100644 --- a/src/NEOs.jl +++ b/src/NEOs.jl @@ -11,7 +11,7 @@ import SatelliteToolboxTransformations.sv_ecef_to_ecef import Downloads using Distributed, JLD2, TaylorIntegration, Printf, DelimitedFiles, Test, LinearAlgebra, - Dates, SPICE, Quadmath, LazyArtifacts, TaylorSeries, + Dates, SPICE, Quadmath, LazyArtifacts, TaylorSeries, JSON, InteractiveUtils, AutoHashEquals, Scratch using PlanetaryEphemeris: daysec, su, ea, α_p_sun, δ_p_sun, t2c_jpl_de430, pole_rotation, au, c_au_per_day, R_sun, c_cm_per_sec, c_au_per_sec, yr, RE, TaylorInterpolant, Rx, diff --git a/src/observations/radec_mpc.jl b/src/observations/radec_mpc.jl index 4e6d2d3e..cf51e34b 100644 --- a/src/observations/radec_mpc.jl +++ b/src/observations/radec_mpc.jl @@ -502,15 +502,28 @@ end Download MPC optical astrometry of NEO `id` and save the output to `filename`. """ function get_radec_mpc(id::AbstractString, filename::AbstractString = replace(id, " " => "_") * ".txt") - # MPC search url - search_url = search_mpc_url * replace(id, " " => "+") - # MPC observations file url - obs_url = obs_mpc_url * replace(id, " " => "_") * ".txt" - # Download database search - download(search_url, filename) - # Download observations file - download(obs_url, filename) - return nothing + # HTTP query + resp = get( + "http://minorplanetcenter.net/search_db"; + query = ["table" => "observations", "designation" => id] + ) + # Converty to String + text = String(resp.body) + # Parse JSON + obs = JSON.parse(text) + # Find matches + matches = Vector{RegexMatch}(undef, length(obs)) + for i in eachindex(obs) + s = obs[i]["original_record"] + matches[i] = match(mpc_radec_regex, s) + end + filter!(!isnothing, matches) + # Parse RadecMPC + radec = RadecMPC.(matches) + # Write observations to file + write_radec_mpc(radec, filename) + + return radec end # Methods to convert a Vector{<:AbstractAstrometry} to a DataFrame