Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kanye REST
#1
Below is some code to grab a random Kanye "Ye" West quote:

Code: (Select All)
Option Explicit
$NoPrefix
$Console:Only
$Unstable:Http

Dim As Long connection: connection = OpenClient("HTTP:https://api.kanye.rest/")
If connection <> 0 And StatusCode(connection) = 200 Then
    Dim As String buf, outbuf
    While Not EOF(connection)
        Get connection, , buf
        outbuf = outbuf + buf
    Wend
    outbuf = Mid$(outbuf, 11)
    outbuf = Mid$(outbuf, 1, Len(outbuf) - 2)
    Print outbuf
    Print: Print "-Kanye West"
End If
Tread on those who tread on you

Reply
#2
Note: This needs the latest GitHub build to run.  It won't work in version 3.4.1, just FYI.
Reply
#3
you can get the quotes from https://github.com/ajzbc/kanye.rest/blob...uotes.json
Reply
#4
Yeah, I'm just trying to show how easy it is to use the new features in QB64pe
Tread on those who tread on you

Reply
#5
in the early Mac computer there was a program available that would at random times pop-up Bullwinkle the moose an say something silly/funny
see https://en.wikipedia.org/wiki/Bullwinkle_J._Moose
https://www.wired.com/2001/08/hey-mac-th...-is-loose/
Reply
#6
Time to get out yer shovels when the moose is loose. -Kenye
b = b + ...
Reply
#7
Requires the file "quotes.json". If it's in the same format it doesn't matter who the speaker was, does it?

Code: (Select All)
$CONSOLE:ONLY
dim as long ff, ll, l, ts

ts = (val(mid$(time$, 4, 2)) mod 2) * 60 + val(right$(time$, 2))

afile$ = "quotes.json"
ff = freefile
open afile$ for input as ff
do until eof(ff)
    line input #ff, aline$
    if aline$ = "[" then
        ll = 0
    elseif aline$ = "]" then
        exit do
    else
        ll = ll + 1
    end if
loop
close ff

redim sf$(1 to ll)
ff = freefile
open afile$ for input as ff
do until eof(ff)
    line input #ff, aline$
    if aline$ = "[" then
        l = 0
    elseif aline$ = "]" then
        exit do
    else
        l = l + 1
        aline$ = _trim$(aline$)
        if l = ll then
            sf$(l) = mid$(aline$, 2, len(aline$) - 2)
        else
            sf$(l) = mid$(aline$, 2, len(aline$) - 3)
        end if
    end if
loop
close ff

print sf$(ts)
print "- Kanye West"
system
Reply
#8
Yep, you definitely can read a JSON file in QB64pe
Tread on those who tread on you

Reply
#9
oh i get it. Kanye REST - Kanye WEST.

CLEVER. Also thanks for sharing.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply




Users browsing this thread: 2 Guest(s)