Warning: fopen(/www/htdocs/w0135691/api.json-content-importer.com/wp-content/cache/jsoncontentimporterpro/41c828e77538d56dd996974bffd53e5e.cgi): Failed to open stream: Permission denied in /www/htdocs/w01dd09b/api.json-content-importer.com/wp-content/plugins/jsoncontentimporterpro3/class-fileload-cache-pro.php on line 491
PRO: Openweather Forecast – search location, show weather – Supportsite JSON Content Importer

PRO: Openweather Forecast – search location, show weather

Challenge:
Show current and forecast weather data via
https://api.openweathermap.org/data/2.5/onecall?lat={{lat}}&lon={{lon}}&exclude={part}&appid=….
for a searchable location.

Solution:
Use the above API for the weather at a location defined by lat and lon. Also use the openweather-geocoding API to transform a locationname into lat & lon.

In Action:

cache-error:
/www/htdocs/w0135691/api.json-content-importer.com/wp-content/cache/jsoncontentimporterpro/41c828e77538d56dd996974bffd53e5e.cgi
is either empty or unwriteable – plugin aborted

See how this is done with a JCI-Shortcode:

[jsoncontentimporterpro nameoftemplate="openweather-forecast"]

With this JCI-template:

  • urlparam4twig: su
  • URL:
{% set su = "augsburg" %}{% if urlparam.su %}{% set su = urlparam.su %}{% endif %}
http://api.openweathermap.org/geo/1.0/direct?q={{su}}&limit=10&appid=...
{% set su = "augsburg" %}{% if urlparam.su %}{% set su = urlparam.su %}{% endif %}
<form action=".">
    <input type=text name=su placeholder="Insert name of a location" value="{{su}}">
    <input type=submit value="Search location and weather">
</form>
<hr>
{% for l in _context %}
    {% if l.lat %}
        {{l.name}} ({{l.country}}
        {% if l.state %}
            , {{l.state}}
        {% endif %})
        <a href="https://www.google.com/maps/place//@{{l.lat}},{{l.lon}},14z" target="_blank">show on map</a>
        |
        <a href="/openweather-forecast/?lat={{l.lat}}&lon={{l.lon}}&su={{l.name|e|url_encode}}">show weather</a>
        <br>
    {% endif %}
{% endfor %}