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 (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/container"
|
||||
|
@ -23,40 +22,57 @@ type vehicle struct {
|
|||
equipment string
|
||||
}
|
||||
|
||||
func getVehicleByNum(vehicleNum int) 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
|
||||
c := colly.NewCollector(
|
||||
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"),
|
||||
)
|
||||
dataIndex := 0
|
||||
c.OnHTML(".vehicle-details-entry-value", func(e *colly.HTMLElement) {
|
||||
text := e.Text
|
||||
retrievedData[dataIndex] = text
|
||||
dataIndex++
|
||||
c2.OnHTML(".grid-row-active", func(e *colly.HTMLElement) {
|
||||
text := e.Attr("href")
|
||||
vehicleURL = text
|
||||
})
|
||||
c.Visit(vehicleURL)
|
||||
c2.Visit(searchURL)
|
||||
if searchURL == "" {
|
||||
return ""
|
||||
} else {
|
||||
var retrievedData [10]string
|
||||
// Instantiate default collector
|
||||
c := colly.NewCollector(
|
||||
// Visit only domains:
|
||||
colly.AllowedDomains("www.ztm.waw.pl"),
|
||||
)
|
||||
dataIndex := 0
|
||||
c.OnHTML(".vehicle-details-entry-value", func(e *colly.HTMLElement) {
|
||||
text := e.Text
|
||||
retrievedData[dataIndex] = text
|
||||
dataIndex++
|
||||
})
|
||||
c.Visit(vehicleURL)
|
||||
retrievedVehicle := vehicle{
|
||||
producer: retrievedData[0],
|
||||
model: retrievedData[1],
|
||||
production_year: retrievedData[2],
|
||||
traction_type: retrievedData[3],
|
||||
vehicle_registration_plate: retrievedData[4],
|
||||
vehicle_number: retrievedData[5],
|
||||
operator: retrievedData[6],
|
||||
garage: retrievedData[7],
|
||||
ticket_machine: retrievedData[8],
|
||||
equipment: retrievedData[9],
|
||||
}
|
||||
|
||||
retrievedVehicle := vehicle{
|
||||
producer: retrievedData[0],
|
||||
model: retrievedData[1],
|
||||
production_year: retrievedData[2],
|
||||
traction_type: retrievedData[3],
|
||||
vehicle_registration_plate: retrievedData[4],
|
||||
vehicle_number: retrievedData[5],
|
||||
operator: retrievedData[6],
|
||||
garage: retrievedData[7],
|
||||
ticket_machine: retrievedData[8],
|
||||
equipment: retrievedData[9],
|
||||
output_string := fmt.Sprintf(
|
||||
`%s %s
|
||||
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
|
||||
}
|
||||
output_string := fmt.Sprintf(
|
||||
`%s %s
|
||||
`, retrievedVehicle.producer, retrievedVehicle.model)
|
||||
return output_string
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -70,10 +86,12 @@ func main() {
|
|||
{Text: "Podaj numer taborowy pojazdu:", Widget: entry}},
|
||||
}
|
||||
form.OnSubmit = func() {
|
||||
input, error := strconv.Atoi(entry.Text)
|
||||
fmt.Println(error)
|
||||
output.Text = getVehicleByNum(input)
|
||||
|
||||
output_data := getVehicleByNum(entry.Text)
|
||||
if output_data != "" {
|
||||
output.Text = output_data
|
||||
} else {
|
||||
output.Text = "Nie znaleziono pojazdu o podanym numerze taborowym w bazie pojazdów WTP"
|
||||
}
|
||||
output.Refresh()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue