Skip to content

Instantly share code, notes, and snippets.

@ashim888
Last active January 18, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashim888/9a87324d1092ff36d4d6f572755313c4 to your computer and use it in GitHub Desktop.
Save ashim888/9a87324d1092ff36d4d6f572755313c4 to your computer and use it in GitHub Desktop.
'automatical movement based on mathematical formulas.....
'(c) fbr@vizrt.com
dim target as container = Scene.FindContainer("Result")
sub OnInitParameters()
'create the GUI
RegisterParameterString("url", "URL:","http://cricket.yarsha.net", 50,255, "")
RegisterParameterString("page", "Page:","/api/test", 50,255, "")
RegisterParameterString("catch","Parse for:","<name>",50,255,"")
RegisterPushButton("get","Download",1)
end sub
sub OnExecAction(buttonId As Integer)
'if user hits the downloadbutton, grab the XML file
Download()
end sub
sub Download()
dim url, page as string
dim result as string
dim port as Integer = 80
'get the values
url=GetParameterString("url")
page=GetParameterString("page")
'create a connection to the host at port 80 (HTTP), GET the file, set timeout to 900
result = system.TcpSend(url, port, "GET " & page & " HTTP/1.0\r\nHost: " & url & ":" & port & "\r\n\r\n", 1000)
'then parse the result
TeamLineUp(result)
'parseXML(result)
end sub
sub TeamLineUp(input as string)
dim i as integer
dim lines,new_dict as array [string]
dim dict,text,team1,team2 as string
dim player0 ,player1, player2 as string
'println "result" &input
input.split("\n",lines)
'dim lastindex as integer = lines.ubound
'dict = lines[lastindex-1]
'lines[lastindex-1].split("><",new_dict)
target.geometry.text=""
for i=0 to lines.ubound
if lines[i].Find("<team1>")<>-1 then
team1 = lines[i]
team1=team1.GetSubString(team1.Find("<team1>"),team1.Find("</team1>"))
println"" &team1&"\n"
player0 = team1.GetSubString(team1.Find("<player0>"),team1.Find("</player0>"))
player0 = player0.GetSubString(player0.Find("<name>"),player0.Find("</name>"))
player0=player0.left(player0.length-9)
player0=player0.right(player0.length-6)
println "player0 Name: " &player0
player1 = team1.GetSubString(team1.Find("<player1>"),team1.Find("</player1><"))
player1 = player1.GetSubString(player1.Find("<name>"),player1.Find("</name>"))
player1=player1.left(player1.length-9)
player1=player1.right(player1.length-6)
println "player1 Name: " &player1
player2 = team1.GetSubString(team1.Find("<player2>"),team1.Find("</player2><"))
player2 = player2.GetSubString(player2.Find("<name>"),player2.Find("</name>"))
player2=player2.left(player2.length-9)
player2=player2.right(player2.length-6)
println "player2 Name: " &player2
target.geometry.text=target.geometry.text&"\n"&player0&"\n"&player1&"\n"&player2
end if
println "\n"
if lines[i].Find("<team2>")<>-1 then
team2 = lines[i]
team2=team2.GetSubString(team2.Find("<team2>"),team2.Find("</team2>"))
'println "team2: " &team2
end if
next
end sub
sub ParseXML(input as string)
'println "result" &input
dim lines as array [string]
dim i as integer
dim text,catch as string
catch =GetParameterString("catch")
'split everything into an array
input.split("\n",lines)
'clear the output field
target.geometry.text=""
'go through the array line by line
for i=0 to lines.ubound
'if the current line contains a <title>..
'println "Lines[i]" &lines[i].Find(catch)
if lines[i].Find(catch)<>-1 then
text=lines[i]
'search for the first occurence of ">" and truncate it
text=text.GetSubString(text.FindFirstOf(">")+1,text.length)
'then truncate it from the right side by 8 characters
text=text.left(text.length-8)
'save the text to the result container
target.geometry.text=target.geometry.text&"\n"&text
end if
next
'println "Catch: " &catch
'println "text: " &text
end sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment