aberger3647 / moon-gaze

Discover what phase the moon is in and if moon-gazing conditions are favorable in your area.
MIT License
0 stars 0 forks source link

dark sky places #5

Open aberger3647 opened 1 month ago

aberger3647 commented 1 month ago

You'd probably need to do some caching. You want to show people their nearest dark sky locations right? Aside from the initial GET request that loads the page (which already has a chunk of locations in it), the search/querying done on the site is using a POST request to their search endpoint

Image

POST https://darksky.org/wp-json/facetwp/v1/refresh

Example body:

{
  "action": "facetwp_refresh",
  "data": {
    "facets": {
      "select_a_place_type": [],
      "location_dropdown": [
        "southwest-united-states"
      ],
      "search_field": "",
      "load_more": []
    },
    "frozen_facets": {
      "location_dropdown": "soft"
    },
    "http_params": {
      "get": {
        "_location_dropdown": "southwest-united-states"
      },
      "uri": "what-we-do/international-dark-sky-places/all-places",
      "url_vars": []
    },
    "template": "dark_sky_places",
    "extras": {
      "sort": "default"
    },
    "soft_refresh": 0,
    "is_bfcache": 1,
    "first_load": 0,
    "paged": 1
  }
}
aberger3647 commented 1 month ago

Two difficulties: This is only going to give you a page of responses. To get every location, you'd probably need to submit repeated POSTS and change the value of paged to 2, 3, 4, ... 1a. You can reduce the number of calls necessary by using their _location_dropdown filter, if you have a rough idea of where on earth your user is. So you're not querying locations in Europe for someone in Austin

aberger3647 commented 1 month ago

The response you get from the POST request looks just like HTML intended to be dumped/rendered onto the page. It doesn't appear to be nice clean JSON data. So you may have to use an XML or HTML parsing library

Here is a screenshot of the response. Looks like it also includes some useful pagination data

Image

I don't know if the location data is within that template field. Maybe not. But it should at least have a link to the location's web page, which has a Google Maps link/ID: https://darksky.org/places/horseshoe-bay-texas-dark-sky-community/

There are lat/lon coordinates in the Weather paragraph which you can parse, but I don't know if they're exact to the dark sky location, or a nearby landmark. The one in the link above says:

Click here to find ideal environmental conditions for viewing the night sky in Horseshoe Bay, TX (30.53942, -98.37222). Don’t forget to plan your trip during the new moon and astronomical twilight to enhance the viewing experience!