Hi! I’m trying to run a quote of the day text field. I hosted my custom xml file on github to be able to have api authentication when searching for the file.
But the formula only fetch the first quote. It won’t randomly change the quote each days. I’ve tried many thing but no one working (thanks gpt ). Do you guys have an idea how I can do this?
Hi there,
Do you mind sharing the content structure of your XML data? It would help us to identify your issue.
Also, your script retrieves the whole content of the XML file, you need to use the following function to randomly get the index number of the quote data:
$tu(rnd, int, from, to)$
NOTES
- int: time interval in minute(s) ➞ 1, 2, …
- from: lowest number in range ➞ any integer number
- to: highest number in range ➞ any integer number larger than the from
EXAMPLE
$tu(rnd, 1, 10, 20)$
➞ Show random number between 10 and 20, every 1 minute
I hope this would help.
Here’s the link to my xml file: https://gist.githubusercontent.com/BlueStarOne/99ba26be57424ef9b6426a77bad59a81/raw/starwars_quotes.xml
Also, how do I integrate your formula? Like this? $wg(“filepath/starwars_quotes.xml”, xml, “//quote/text[$tu(rnd, int, from, to)$]”)$
Thanks for the help
Edit : can I choose an hour at which to change the quote instead of a time after which it changes? Like it would change each days at midnight
Hi there,
Here’s is my code snippet for getting & displaying a random quote, from a local XML data file.
$
lv(idx, tu(rnd,10,1,5))
$$
wg(
"file:///sdcard/Kustom/starwars_quotes.xml"
,xml
,"//quotes/quote["+#idx+"]/text"
)
$
by $
wg(
"file:///sdcard/Kustom/starwars_quotes.xml"
,xml
,"//quotes/quote["+#idx+"]/author"
)
$
Screenshot: The script
Screenshot: The result
NOTES
- The XML data file for the example is located in the Kustom folder.
- The time interval is set every 10 minutes, in
tu(rnd, 10, 1, 5)
. Set it to 1440 for 24-hour interval (24 × 60 min) - The 3rd and 4th parameter in
tu(rnd, 10, 1, 5)
is set to: 1 and 5 ➞ 5 quotes in the XML file. Replace the 4th parameter with the number of quotes you have in the XML file.
I hope this would help.
Ayoo thank you so much it works perfectly now
Thanks