Hi, I'm getting text from a website at the press of a button, but it seems way too slow and not async.
The data is being downloaded from a website that cointains plain text only, it is filtered in order to display only what matters to me and I replace the weed days from english to italian.
The output is never bigger than 20 lines
The code is fully tested and It does its work.
But it is very slow, to complete the output it takes not less than 20 s.
Is there a way to make it faster? Thanks
The code is
The data is being downloaded from a website that cointains plain text only, it is filtered in order to display only what matters to me and I replace the weed days from english to italian.
The output is never bigger than 20 lines
The code is fully tested and It does its work.
But it is very slow, to complete the output it takes not less than 20 s.
Is there a way to make it faster? Thanks
The code is
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private Edittext1 As EditText
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
ScaricaTestoEFiltra
End Sub
Sub ScaricaTestoEFiltra()
Try
Dim url As String = "mywebsite.com"
Dim j As HttpJob
j.Initialize("", Me)
j.Download(url)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log("Download success")
Dim testoFiltrato As StringBuilder
testoFiltrato.Initialize
Dim lines() As String = Regex.Split("\n", j.GetString)
For Each linea As String In lines
Dim matcher1 As Matcher = Regex.Matcher("(.*hd7\.php.*|.*hd8\.php.*)", linea)
If matcher1.Find Then
Log("Match found: " & linea)
testoFiltrato.Append(linea).Append(CRLF).Append(CRLF)
Else
Dim giorniSettimana() As String = Array As String("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY")
For Each giorno As String In giorniSettimana
If linea.Contains(giorno) Then
Log("Day found: " & giorno)
linea = linea.Replace(giorno, TraduciGiorno(giorno))
testoFiltrato.Append(linea).Append(CRLF)
Exit
End If
Next
End If
Next
Edittext1.Text = testoFiltrato.ToString
Else
Log("Download failed")
End If
j.Release
Catch
Log("Error: " & LastException.Message)
End Try
End Sub
Sub TraduciGiorno(giorno As String) As String
Select giorno
Case "MONDAY"
Return "LUNEDI"
Case "TUESDAY"
Return "MARTEDI"
Case "WEDNESDAY"
Return "MERCOLEDI"
Case "THURSDAY"
Return "GIOVEDI"
Case "FRIDAY"
Return "VENERDI"
Case "SATURDAY"
Return "SABATO"
Case "SUNDAY"
Return "DOMENICA"
Case Else
Return giorno
End Select
End Sub