Horoscopes on an ILI9341 - From old forum.
Posted: Sat May 15, 2021 8:41 pm
This is a daft project from the old forum when I was exploring free APIs.
There is a problem with the API in that it truncates the output if the line contains a colon. Nothing I can do about that.
My horoscope in the pic was encouraging me to travel to new and exotic places, just after the UK entered it's first hard covid lockdown
There is a problem with the API in that it truncates the output if the line contains a colon. Nothing I can do about that.
My horoscope in the pic was encouraging me to travel to new and exotic places, just after the UK entered it's first hard covid lockdown
Code: [Local Link Removed for Guests]
' =============================
' Annex Basic Daily Horoscopes.
' =============================
' Displays on ILI9341 - Landscape mode.
' Uses unofficial API getting data from astrology.com so may drop dead.
pause 400
TFT.INIT 16, 4, 1 ' May need 16,4,3 depending on screen orientation.
TFT.FILL &H0
TFT.TEXT.COL 55120, 50
TFT.TEXT.SIZE 1
pause 200
Dim Signs$(12) = "aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn", "aquarius", "pisces"
LF$ = chr$(10)
do
Sel = (Sel + 1) mod 12
Query$ = "ohmanda.com/api/horoscope/" + Signs$(Sel) + "/"
Line$ = wget$(Query$,80)
Line$ = replace$(Line$, "\""", "'") ' Replace double quotes with single.
Sign$ = json$(Line$,"sign")
HDate$ = json$(Line$,"date")
Horo$ = json$(Line$,"horoscope")
Horo$ = right$(Horo$,len(Horo$)-1)
WCnt = word.count(Horo$)
DspLine$ = ""
PDate$ = right$(HDate$,2) + "-" + mid$(HDate$,6,2) + "-" + left$(HDate$,4) ' dd-mm-yyyy format.
tft.fill 50
tft.text.pos 0,10
tft.print " " + ucase$(Sign$)
tft.text.pos 240,10
tft.print PDate$
tft.print " " + string$(len(Sign$),"-")
tft.text.pos 240,18
tft.print string$(10,"-") + LF$ + LF$
for cnt = 1 to WCnt
NewWrd$ = word$(Horo$,cnt)
if len(DspLine$) + len(NewWrd$) >51 then
DspLine$ = " " + left$(DspLine$ + " ",51) + LF$
tft.print DspLine$
DspLine$ = ""
cnt = cnt - 1
else
DspLine$ = DspLine$ + NewWrd$ + " "
end if
next Cnt
tft.print " " + DspLine$
pause 30000
loop