Finished searching, added action on non-existing vehicle
This commit is contained in:
parent
58173ba295
commit
48eeb55dde
2 changed files with 53 additions and 33 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
fyne_metadata_init.go
|
||||||
|
ztm_vehicles_app.apk
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
|
@ -23,11 +22,22 @@ type vehicle struct {
|
||||||
equipment string
|
equipment string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVehicleByNum(vehicleNum int) string {
|
func getVehicleByNum(vehicleNum string) string {
|
||||||
|
searchURL := fmt.Sprintf("https://www.ztm.waw.pl/baza-danych-pojazdow/?ztm_traction=&ztm_make=&ztm_model=&ztm_year=&ztm_registration=&ztm_vehicle_number=%s&ztm_carrier=&ztm_depot=", vehicleNum)
|
||||||
|
vehicleURL := ""
|
||||||
|
c2 := colly.NewCollector(
|
||||||
|
// Visit only domains:
|
||||||
|
colly.AllowedDomains("www.ztm.waw.pl"),
|
||||||
|
)
|
||||||
|
c2.OnHTML(".grid-row-active", func(e *colly.HTMLElement) {
|
||||||
|
text := e.Attr("href")
|
||||||
|
vehicleURL = text
|
||||||
|
})
|
||||||
|
c2.Visit(searchURL)
|
||||||
|
if searchURL == "" {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
var retrievedData [10]string
|
var retrievedData [10]string
|
||||||
|
|
||||||
//get data from website and insert it into array
|
|
||||||
vehicleURL := fmt.Sprintf("https://www.ztm.waw.pl/baza-danych-pojazdow/?ztm_mode=2&ztm_vehicle=%d", vehicleNum)
|
|
||||||
// Instantiate default collector
|
// Instantiate default collector
|
||||||
c := colly.NewCollector(
|
c := colly.NewCollector(
|
||||||
// Visit only domains:
|
// Visit only domains:
|
||||||
|
@ -40,7 +50,6 @@ func getVehicleByNum(vehicleNum int) string {
|
||||||
dataIndex++
|
dataIndex++
|
||||||
})
|
})
|
||||||
c.Visit(vehicleURL)
|
c.Visit(vehicleURL)
|
||||||
|
|
||||||
retrievedVehicle := vehicle{
|
retrievedVehicle := vehicle{
|
||||||
producer: retrievedData[0],
|
producer: retrievedData[0],
|
||||||
model: retrievedData[1],
|
model: retrievedData[1],
|
||||||
|
@ -53,10 +62,17 @@ func getVehicleByNum(vehicleNum int) string {
|
||||||
ticket_machine: retrievedData[8],
|
ticket_machine: retrievedData[8],
|
||||||
equipment: retrievedData[9],
|
equipment: retrievedData[9],
|
||||||
}
|
}
|
||||||
|
|
||||||
output_string := fmt.Sprintf(
|
output_string := fmt.Sprintf(
|
||||||
`%s %s
|
`%s %s
|
||||||
`, retrievedVehicle.producer, retrievedVehicle.model)
|
z roku %s,
|
||||||
|
w posiadaniu %s,
|
||||||
|
z zajezdni %s,
|
||||||
|
o rejestracji %s
|
||||||
|
`, retrievedVehicle.producer, retrievedVehicle.model, retrievedVehicle.production_year, retrievedVehicle.operator, retrievedVehicle.garage, retrievedVehicle.vehicle_registration_plate)
|
||||||
return output_string
|
return output_string
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -70,10 +86,12 @@ func main() {
|
||||||
{Text: "Podaj numer taborowy pojazdu:", Widget: entry}},
|
{Text: "Podaj numer taborowy pojazdu:", Widget: entry}},
|
||||||
}
|
}
|
||||||
form.OnSubmit = func() {
|
form.OnSubmit = func() {
|
||||||
input, error := strconv.Atoi(entry.Text)
|
output_data := getVehicleByNum(entry.Text)
|
||||||
fmt.Println(error)
|
if output_data != "" {
|
||||||
output.Text = getVehicleByNum(input)
|
output.Text = output_data
|
||||||
|
} else {
|
||||||
|
output.Text = "Nie znaleziono pojazdu o podanym numerze taborowym w bazie pojazdów WTP"
|
||||||
|
}
|
||||||
output.Refresh()
|
output.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue