Post by mark on Jun 10, 2020 0:09:36 GMT -5
Hi, I want to try to create a lottery program using the Virginia Pick 3 lottery game. I thought this might be a good program to learn the Liberty Basic code better by doing. I am just getting started and to begin I wanted to download the previous drawn numbers. I tried using a code I found on this message board but I couldn't get it to work right.
The code I used was:
I tried it with a normal link to a website and it seems to work, But when using this link it will not. This link on the website normally downloads a .txt file with previously drawn numbers. Is there a way to get this or some other code to download and read the .txt file? Or maybe if I downloaded the file be able to read the text file from my desktop or something similar. Any suggestions or ideas would be appreciated.
This is what the txt file looks like after downloading it (partial) from the lottery website. Va Lottery Link
6/9/2020; Day: 9,1,6; Night: 4,1,0
6/8/2020; Day: 9,4,1; Night: 4,2,1
6/7/2020; Day: 7,8,5; Night: 3,9,7
6/6/2020; Day: 2,2,6; Night: 1,7,7
6/5/2020; Day: 9,0,5; Night: 4,3,0
6/4/2020; Day: 3,2,5; Night: 4,3,7
6/3/2020; Day: 3,9,6; Night: 3,5,3
6/2/2020; Day: 0,4,1; Night: 0,9,5
6/1/2020; Day: 9,4,2; Night: 3,9,5
5/31/2020; Day: 1,5,1; Night: 1,5,4
I would like to extract the numbers to write to another text file something like for the program to read:
916
410
941
421
785
397
etc
etc
The code I used was:
asxcode$="BHP"
selmonth$="Jun"
year$="2020"
global asxcode$,selmonth$,year$
call Table2CSV asxcode$
WAIT
' --------------------------------------
SUB Table2CSV asxcode$
' change this to your web page
'webPage$ = "https://www.valottery.com/sitecore/shell/api/sitecore/DrawPastNumbers/DownloadAll?gameId=1050"
webPage$="https://www.valottery.com/sitecore/shell/api/sitecore/DrawPastNumbers/DownloadAll?gameId=1050"
' change this to your output csv file name
print webPage$
fileName$ = asxcode$
htmlData$ = httpget$(webPage$)
lowData$ = lower$(htmlData$)
open DefaultDir$+"\"+"DATA\"+ fileName$+".txt" for output as #f
[nxtTbl]
tblBeg = instr(lowData$,"<table",tblEnd)
if tblBeg = 0 then goto [endTbl]
tblEnd = instr(lowData$,"</table>",tblBeg)
tblData$ = mid$(htmlData$,tblBeg,(tblEnd - tblBeg) + 8)
lineBeg = 0
lineEnd = instr(tblData$,"</tr>",lineBeg)
while lineEnd > 0
lineData$ = mid$(tblData$,lineBeg - 1,(lineEnd - lineBeg) + 1)
lineData$ = strip$(lineData$)
lineData$ = strRep$(lineData$,"</td>",",")
lineData$ = strRep$(lineData$,"</th>",",")
lineData$ = tags$(lineData$,"")
lineData$ = strRep$(lineData$," "," ")
lineData$ = strRep$(lineData$,"&","and")
print "";left$(lineData$,len(lineData$) -2)
print #f, "";left$(lineData$,len(lineData$) -2)
lineBeg = lineEnd + 1
lineEnd = instr(tblData$,"</tr>",lineBeg)
wend
print "----------------- end <table> --------------------------"
goto [nxtTbl]
[endTbl]
close #f
END SUB
' -----------------------------------------
' strip junk
' -----------------------------------------
FUNCTION strip$(str$)
strip$ = ""
for i = 1 to len(str$)
a$ = MID$(str$,i,1)
a = ASC(a$)
if a > 31 then
if a < 127 then
if a$ <> "'" then
if a$ <> "" then
strip$ = strip$ + a$
end if
end if
end if
end if
next i
END FUNCTION
' --------------------------------
' string replace rep str with
' --------------------------------
FUNCTION strRep$(str$,rep$,with$)
ln = len(rep$)
ln1 = ln - 1
i = 1
while i <= len(str$)
if mid$(str$,i,ln) = rep$ then
strRep$ = strRep$ + with$
i = i + ln1
else
strRep$ = strRep$ + mid$(str$,i,1)
end if
i = i + 1
WEND
END FUNCTION
' --------------------------------
' Replace HTML <tags> with$
' --------------------------------
FUNCTION tags$(tag$,with$)
i = instr(tag$,"<")
j = instr(tag$,">",i)
WHILE j > i
tag$ = left$(tag$,i - 1) + mid$(tag$,j + 1)
i = instr(tag$,"<")
j = instr(tag$,">")
WEND
tags$ = tag$
END FUNCTION
I tried it with a normal link to a website and it seems to work, But when using this link it will not. This link on the website normally downloads a .txt file with previously drawn numbers. Is there a way to get this or some other code to download and read the .txt file? Or maybe if I downloaded the file be able to read the text file from my desktop or something similar. Any suggestions or ideas would be appreciated.
This is what the txt file looks like after downloading it (partial) from the lottery website. Va Lottery Link
6/9/2020; Day: 9,1,6; Night: 4,1,0
6/8/2020; Day: 9,4,1; Night: 4,2,1
6/7/2020; Day: 7,8,5; Night: 3,9,7
6/6/2020; Day: 2,2,6; Night: 1,7,7
6/5/2020; Day: 9,0,5; Night: 4,3,0
6/4/2020; Day: 3,2,5; Night: 4,3,7
6/3/2020; Day: 3,9,6; Night: 3,5,3
6/2/2020; Day: 0,4,1; Night: 0,9,5
6/1/2020; Day: 9,4,2; Night: 3,9,5
5/31/2020; Day: 1,5,1; Night: 1,5,4
I would like to extract the numbers to write to another text file something like for the program to read:
916
410
941
421
785
397
etc
etc