NotePlan / plugins

The main NotePlan repository, which contains the source code for all NotePlan plugins. If a release entry has been created, it will be available for installation from within NotePlan application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Location for Weather

Elwood4415 opened this issue · comments

Describe the bug
When attempting to show the weather in the daily note template using the Templating function, it provides a location hundreds of miles from my actual location.

To Reproduce
Add weather code suggested by the Templating help document to the daily note template
Use the template/daily note command to create a note

Expected behavior
Would show my actual location rather than a location at the other end of the state

System

  • Device: Mac
  • OS: MacOS Sonoma
  • NotePlan Version: NotePlan beta Version 3.9.8 (1118)
  • Plugin Name & Version Templating v1.9.12

Additional context
Location services are working for my Mac, and other apps use the correct location. I have attempted to find any location permissions applicable to NotePlan, but cannot find any.

Plugin Console Log
To provide us with more clues about where the bug/error is occurring...

  1. Open the Plugin's Preferences by going to NotePlan's menu > Preferences > Plugins and clicking the settings "cog" icon next to the plugin in question. Scroll to the bottom and set the logging level to "DEBUG" and click "Save & Close"
  2. Now open the Plugin Console by going to Noteplan > Help > Plugin Console
  3. Run the plugin command you're reporting
  4. Copy the output from the Plugin Console and paste it below
  5. Delete any output that has personal information you don't want in there
  Executing function 'onSettingsUpdated'
  Executing function 'insertNoteTemplate'
  Executing function 'listDaysEvents'

I wrote the original weather integration in a plugin, though I think what is available now is different. However, I think the principles are the same, so let me comment.
Plugins run in a very restricted sandbox and don't have any access to the rest of macOS other than some specific channels that the NP developer opens up via an API. Recently that has included some window management calls.
One thing it can do is call web services, and so that's what's happening. The call will be to a free service, and the geolocation comes from your IP address, which in your case might be a hub from your internet provider. There should be a way of specifying a more exact lat/long, or city name, but I don't know the details.

Thanks for the response. I failed to mention it in my original post, but I tried adding my actual location in the Templating plug-in. Unfortunately, that didn't help matters. This is not something that is a big deal. I just thought I would play around with it a bit.

You can request a lat long based weather if you make a free openweather api key and this template

<% const config = { openWeatherAPIKey: "APIKEY", lat: "00.0000",long: "00.0000", units: "imperial"} -%> <% const weatherURL =https://api.openweathermap.org/data/2.5/onecall?lat=${config.lat}&lon=${config.long}&exclude=current,hourly,minutely&units=${config.units}&appid=${config.openWeatherAPIKey}` -%>
<% const jsonIn = await fetch(weatherURL); -%>
<% const allWeatherData = JSON.parse(jsonIn); -%>
<% const weatherTodayAll = allWeatherData?.daily['0']; -%>
<% const fMax = weatherTodayAll.feels_like.day.toFixed(0); -%>
<% const fMin = weatherTodayAll.feels_like.night.toFixed(0); -%>
<% const minTemp = weatherTodayAll.temp.min.toFixed(0); -%>
<% const maxTemp = weatherTodayAll.temp.max.toFixed(0); -%>
<% const weatherDesc = utility.titleCase(weatherTodayAll.weather['0'].description ?? '') -%>
<% const units = config.units === 'imperial' ? '°F' : '°C'; -%>
<% const timezone = allWeatherData.timezone; -%>
<% const weatherLine = ${weatherDesc} ${minTemp}${units}-${maxTemp}${units}; Feels like: ${fMin}${units}-${fMax}${units} -%>
`