willasm / obsidian-open-weather

Obsidian plugin for OpenWeather API
MIT License
47 stars 3 forks source link

How to automatically substitute %weather3% in daily note using Templater? #18

Closed Kablooie98 closed 7 months ago

Kablooie98 commented 8 months ago

Hi, this is mostly a question, not a bug report or feature request.

I'm trying to follow your example https://github.com/willasm/obsidian-open-weather/blob/master/EXAMPLE.md in my daily note (using Templater)

This is what I have:

%weather3%
<%* app.commands.executeCommandById("obsidian-open-weather:replace-template-string")%>

And I don't think this is executing, because when Templater replaces all my template values, the %weather3% string remains as-is in the daily note.

This might just be me not knowing that the syntax of "<%*" does. If this is a call-out to an API, where do I enable it in Obsidian?

Thanks!

willasm commented 8 months ago

Yes I really need to update the example file as it is very out of date. The line with <%* app.commands.executeCommandById("obsidian-open-weather:replace-template-string")%> should be removed as it is not needed. Also the web site https://api.quotable.io/ seems to be down so the daily quote is not working.

Here is what I am currently using... If you need more help getting this working, let me know.

Daily Note Template

---
cssclass: daily, calendar
banner: "![[daily-note-banner.jpg]]"
banner_x: 0.5
banner_y: 0.3
obsidianUIMode: preview
title: <%tp.file.title%>
created: <%tp.date.now()%>
modified: <%tp.date.now()%>
last_reviewed: <%tp.date.now()%>
author: "William McKeever"
source:
status: 
webclip: false
tags: [daily_note]
aliases: []
description: "Daily Note"
---
<div class="weather_historical_3">%weather3%</div>
<div class="weather_current_4"></div>

| <%moment(tp.file.title, 'YYYY-MM-DD').subtract(3, 'd').format('ddd')%> | <%moment(tp.file.title, 'YYYY-MM-DD').subtract(2, 'd').format('ddd')%> | <%moment(tp.file.title, 'YYYY-MM-DD').subtract(1, 'd').format('ddd')%> | <%moment(tp.file.title, 'YYYY-MM-DD').format('ddd')%> | <%moment(tp.file.title, 'YYYY-MM-DD').add(1, 'd').format('ddd')%> | <%moment(tp.file.title, 'YYYY-MM-DD').add(2, 'd').format('ddd')%> | <%moment(tp.file.title, 'YYYY-MM-DD').add(3, 'd').format('ddd')%> |
|:------:|:------:|:------:|:------:|:------:|:------:|:----------:|
|   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(17, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(17, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(16, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(16, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(15, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(15, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(14, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(14, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(13, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(13, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(12, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(12, 'd').format('DD')%>]]   |     [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(11, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(11, 'd').format('DD')%>]]     |
|   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(10, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(10, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(9, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(9, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(8, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(8, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(7, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(7, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(6, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(6, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(5, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(5, 'd').format('DD')%>]]   |     [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(4, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(4, 'd').format('DD')%>]]     |
|   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(3, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(3, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(2, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(2, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(1, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').subtract(1, 'd').format('DD')%>]]   |   ==**[[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').format('DD')%>]]**==   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(1, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(1, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(2, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(2, 'd').format('DD')%>]]   |     [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(3, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(3, 'd').format('DD')%>]]     |
|   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(4, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(4, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(5, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(5, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(6, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(6, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(7, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(7, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(8, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(8, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(9, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(9, 'd').format('DD')%>]]   |     [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(10, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(10, 'd').format('DD')%>]]     |
|   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(11, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(11, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(12, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(12, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(13, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(13, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(14, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(14, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(15, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(15, 'd').format('DD')%>]]   |   [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(16, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(16, 'd').format('DD')%>]]   |     [[Daily/<%moment(tp.file.title, 'YYYY-MM-DD').add(17, 'd').format('YYYY-MM-DD')%>\|<%moment(tp.file.title, 'YYYY-MM-DD').add(17, 'd').format('DD')%>]]     |

> ###### [[<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>|⬅]] <% tp.file.title %> [[<% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %>|➡]]
> ##### 🔹 <% tp.date.now("dddd 🔹 MMMM Do 🔹 YYYY", 0, tp.file.title, "YYYY-MM-DD") %> 🔹
>
<%tp.web.daily_quote()%>

---

## Todo Today
- [ ] `button-review` Review recent notes.

## Achievments for Today

## Research

## Ideas

## Quick notes

DailyNote.css

/*====================*/
/* Daily Note Styling */
/*====================*/
.daily {
    padding-left: 25px !important;
    padding-right: 25px !important;
    padding-top: 20px !important;
}

/* Transition Effect Weather One */
.weather_current_1,
.weather_historical_1 {
  transition: 0.3s;
}

/* Transition Effect Weather Two */
.weather_current_2,
.weather_historical_2 {
  transition: 0.3s;
}

/* Transition Effect Weather Three */
.weather_current_3,
.weather_historical_3 {
  transition: 0.3s;
}

/* Transition Effect Weather Four */
.weather_current_4,
.weather_historical_4 {
  transition: 0.3s;
}

/* Historical & Current weather One, Two, Three and Four common settings */
.weather_historical_1, .weather_current_1, .weather_historical_2, .weather_current_2, .weather_historical_3, .weather_current_3, .weather_historical_4, .weather_current_4 {
    display: flex;
    float: left;
    clear: left;
    align-items: center;
    top: 45px;
    left: 55px;
    white-space: pre;
    position: absolute;
    font-family: monospace;
    font-size: 14pt !important;
    margin: 10px 5px;
    padding: 10px 20px;
    border-radius: 20px;
    box-shadow: 3px 3px 2px #414654;
    cursor: pointer;
}

/* Historical weather at top of the document over banner */
.weather_historical_1, .weather_historical_2, .weather_historical_3, .weather_historical_4 {
    color: #d0dce9;
    background-color: #0d3d56;
}

/* Current weather at top of the document over banner */
.weather_current_1, .weather_current_2, .weather_current_3, .weather_current_4 {
    color: #c4caa5;
    background-color: #133e2c;
    opacity: 0;
}

/* Show Current weather One on hover */
.weather_current_1:hover {
    opacity: 1;
}

/* Show Current weather Two on hover */
.weather_current_2:hover {
    opacity: 1;
}

/* Show Current weather Three on hover */
.weather_current_3:hover {
    opacity: 1;
}

/* Show Current weather Four on hover */
.weather_current_4:hover {
    opacity: 1;
}

/* Daily Note Name H6 Styling (YYYY-MM-DD) */
.daily h6 {
    font-size: 1.75em;
    color: #4cbf90;
    border-width: 1px;
    padding-bottom: 3px;
    text-align: center;
}

/* Daily Note Date H5 Styling (🔹 Thursday 🔹 10th November 🔹 2022 🔹) */
.daily h5 {
    font-size: 1.25em;
    color: #23a49d;
    border-width: 1px;
    padding-bottom: 3px;
    text-align: center;
}

/*==============================*/
/* Display Daily Notes Calendar */
/*==============================*/
.calendar table {
    top: 30px;
    right: 30px;
    position: absolute;
    background-color: #0d3d56;
    border-radius: 10px;
}

.calendar thead {
    background-color: #147980;
}

.calendar th {
    color: goldenrod !important;
}

.calendar table th:first-of-type {
    border-top-left-radius: 6px;
}
.calendar table th:last-of-type {
    border-top-right-radius: 6px;
}

.calendar .internal-link {
    color: rgb(215, 146, 27);
}

.calendar .internal-link.is-unresolved {
    color: silver;
}

.calendar td strong {
    border-radius: 50%;
    padding: 3px;
    border: 2px solid #229ecf;
    color: black !important;
}

.calendar mark {
    /* color: #fd0707 !important; */
    background: #0d3d56;
}

.calendar strong .internal-link{
    color: #23bca5 !important;
    /* background: #0d3d56; */
}

And this is the result I get...

NewDaily

willasm commented 8 months ago

Forgot to add, cssclass in the frontmatter should be changed to cssclasses. Obsidian changed this in v4.0. The old name still works but could be removed at any time.

willasm commented 8 months ago

Just released v1.6.1 with updated EXAMPLE.md file. Also added copies of the files Daily Note.md and dailyNote.css used in EXAMPLE.md file if you need to reference them.

lclarke522 commented 8 months ago

I'm having the same issue. I'm using Templater, and the %weather4% string is not translated. I don't need to put it inside a <div>, do I? I just have it on a line by itself in my template.

# <% tp.date.now("dddd, MMMM Do", 0, tp.file.title, "[Activity Log] YYYY-MM-DD") %>

## Weather
%weather4%

## Summary
- **Clock in**: 
- **Clock out**: 
- **End-of-day satisfaction (1-5)**: 
- **Notes**: 

Gives me this:

Tuesday, January 30th

Weather

%weather4%

Summary

lclarke522 commented 8 months ago

My bad! I got it to work. It looks like OpenWeather didn't recognize my city name. Once I went to their website and found a city close by that they knew, it all started working.

And I love it! Thanks so much for a fantastic plugin!

Weather ☁️

🤩

willasm commented 8 months ago

Glad you got it sorted out. I have just tested this and the API returns a 404 code with the message "city not found" in this situation. I will add a check for this to the plugin. Thanks for bringing this to my attention.

willasm commented 7 months ago

I have just uploaded an updated version that now includes settings for latitude and longitude. This should be helpful in your situation as sending the latitude and longitude to the API will return the weather from the nearest station to you. I have not set a new release yet as I still need to add a check for an error being returned from the API. Hope to get that done today. If you really want to try the new settings the Main.js file here on Github is the newest version. You just need to copy the raw contents to a file named Main.js then move it to the plugins folder. Backup the original file first though, just rename it to something else.

lclarke522 commented 7 months ago

Oh, nice. I will try that next time I'm fiddling around with my notes. Thanks!

willasm commented 7 months ago

This has now been fixed and released as v1.70 Should show up in Obsidian shortly.

Thanks, William.