Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Daily quote is broken - here's a user script alternative

Open mayankguptadotcom opened this issue 2 years ago • 8 comments

Plugin information (please complete the following information):

  • OS: Mac OS X montery
  • Templater version: 1.16.0
  • Obsidian version: 1.1.2

Describe the bug Seems like that api.quoteable.io has been taken down, which causes the daily quote by templater to break.

Expected behavior it should generate daily quote.

Additional context

I've created a user script that gets the quote from brainyquote site instead, for those who can't wait for the fix on templater or for api.quoteable to work, you can use the following script.

copy the below code, and put it in the scripts folder as quote.js

async function quote(value, tp, doc) {
  let url = 'https://www.brainyquote.com/quote_of_the_day';

  if (doc === undefined) {
    let page = await tp.obsidian.request(url);
    let p = new DOMParser();
    doc = p.parseFromString(page, "text/html");
  }

  // Alias for querySelector
  let $ = (s) => doc.querySelector(s);

  switch (value) {
    case "daily":
      return (
        $(".qotd-wrapper-cntr div a div")?.textContent.trim() ||
        "wrong"
      );
     case "author":
      return (
        $(".qotd-wrapper-cntr div .bq-aut")?.textContent.trim() ||
        "wrong"
      );
    default:
      new Notice("Incorrect parameter: " + value, 5000);
  }
}

module. Exports = quote;

and to generate the quote - use the following in your daily note template

> [!quote] <% tp.user.quote('daily', tp) %> ~ <% tp.user.quote('author', tp) %>

mayankguptadotcom avatar Feb 13 '23 22:02 mayankguptadotcom

api.quoteable.io worked until few days ago, now no response at all.

imatosyan avatar Aug 01 '23 08:08 imatosyan

Your script works. Thank you. There is a small typing error module. Exports = quote; should be without space module.Exports = quote;

imatosyan avatar Aug 01 '23 08:08 imatosyan

To keep the format of the previous quote command:

async function quote(tp, doc) {
    let url = 'https://www.brainyquote.com/quote_of_the_day';

    if (doc === undefined) {
        let page = await tp.obsidian.request(url);
        let p = new DOMParser();
        doc = p.parseFromString(page, "text/html");
    }

    // Alias for querySelector
    let $ = (s) => doc.querySelector(s);

    const author = $(".qotd-wrapper-cntr div .bq-aut")?.textContent?.trim() || "author";
    const quot = $(".qotd-wrapper-cntr div a div")?.textContent?.trim() || "quote";

    return `
> ${quot}
> — <cite>${author}</cite>
    `;
}

module.exports = quote;

aVolpe avatar Aug 01 '23 21:08 aVolpe

It seems api.quoteable.io still got certification problem.

curl https://api.quotable.io/random
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

it only works when allowing insecure server

elminsterjimmy avatar Aug 03 '23 08:08 elminsterjimmy

api.quoteable.io is working for me. This ticket can probably be closed

dragos240 avatar Dec 30 '23 17:12 dragos240

api.quotable.io is having DNS resolution issues (since today afternoon).

Edit: never mind it's up again.

tinkerrc avatar Jan 11 '24 04:01 tinkerrc

Thank you @mayankguptadotcom and @aVolpe

For anyone else stumbling on this, as I did when api.quoteable.io went down again...

To keep exactly the same format as the original Templater command, amend @aVolpe's script

    return `
> ${quot}
> — <cite>${author}</cite>
    `;
}

to

    return `> ${quot}
> — <cite>${author}</cite>`;
}

and be sure to call it from your notes with just > [!quote] <% tp.user.quote(tp) %>

peterdalydickson avatar Feb 10 '24 10:02 peterdalydickson

For everyone having this problem, I was able to fix the issue locally.

Depending on your OS, find your hosts file (linux and mac, available at /etc/hosts

Edit the file (Note you might need sudo/root permissions to edit the file and save).

Try any of the following (add only one of the lines at a time, not all. These are all the ip's service lies on)

3.232.242.170 api.quotable.io 54.91.59.199 api.quotable.io 3.220.57.224 api.quotable.io 3.220.57.224 api.quotable.io

Confirm by going to your browser and heading to https://api.quotable.io/random

Enjoy for the time being! While devs get their stuff back up fixed

Edit: I found the IPs by first checking dns for api.quotable.io here Noticing it was a cname, I ran dig mysterious-feijoa-0raf5466fxw0fo43e63hphuv.herokudns.com to find the ips: ;; ANSWER SECTION: mysterious-feijoa-0raf5466fxw0fo43e63hphuv.herokudns.com. 31 IN A 3.232.242.170 mysterious-feijoa-0raf5466fxw0fo43e63hphuv.herokudns.com. 31 IN A 54.91.59.199 mysterious-feijoa-0raf5466fxw0fo43e63hphuv.herokudns.com. 31 IN A 3.220.57.224 mysterious-feijoa-0raf5466fxw0fo43e63hphuv.herokudns.com. 31 IN A 52.20.78.240

CryptoRhinoGH avatar Jul 29 '24 15:07 CryptoRhinoGH