From 9fb9623671bc22c68e56882a8b2a96d059e268b3 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Wed, 27 Aug 2025 17:03:57 +0200 Subject: [PATCH] fix: update data extraction and parsing for availability, permanence, and people in Annuncio --- apps/backend/miogest_handler.go | 10 ++++++++++ apps/backend/parser/parser.go | 9 ++++++--- apps/backend/queries/annunci.go | 16 +++++++++++----- apps/backend/typesdefs/models.go | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/backend/miogest_handler.go b/apps/backend/miogest_handler.go index d0bf152..6415106 100644 --- a/apps/backend/miogest_handler.go +++ b/apps/backend/miogest_handler.go @@ -196,6 +196,16 @@ func extractData_update(annuncio *typesdefs.AnnuncioXML, updateImages bool, m *M tmp.Desc_it = annuncio.Descrizione tmp.Desc_en = annuncio.DescrizioneEn + if annuncio.Dettaglio != nil { + disp, parm, pers, err := parser.ParseDettaglio(*annuncio.Dettaglio) + if err == nil { + tmp.Disponibile_da = disp + tmp.Permanenza = parm + tmp.Persone = pers + + } + } + tmp.Web = boolUpd(true) videos := []string{} diff --git a/apps/backend/parser/parser.go b/apps/backend/parser/parser.go index b5a80a0..6f9bd93 100644 --- a/apps/backend/parser/parser.go +++ b/apps/backend/parser/parser.go @@ -12,6 +12,7 @@ import ( func ParseDettaglio(dettaglio string) (disp_time *string, perm_arr *[]int, persone_arr *[]string, err error) { dettaglio = strings.TrimSpace(dettaglio) + if dettaglio == "" { return } @@ -23,13 +24,14 @@ func ParseDettaglio(dettaglio string) (disp_time *string, perm_arr *[]int, perso persone := getKeyValueUpToXorWhitespace(dettaglio, "persone:", "") if disp != "" { + withAnno := fmt.Sprintf("%s/%d", disp, time.Now().Year()) // Validate date format - _, err := time.Parse("02/01", disp) + t, err := time.Parse("02/01/2006", withAnno) if err != nil { disp_time = nil } else { - p := fmt.Sprintf("%s/%d", disp, time.Now().Year()) - disp_time = &p + formatted := t.Format("02/01/2006") + disp_time = &formatted } } if perm != "" { @@ -101,6 +103,7 @@ func getKeyValueUpToXorWhitespace(input, key, stopstring string) string { if idx := strings.IndexAny(val, " \n\r\t"); idx != -1 { val = val[:idx] } + //fmt.Printf("Extracted value for key '%s': '%s'\n", key, val) return val } diff --git a/apps/backend/queries/annunci.go b/apps/backend/queries/annunci.go index 767c358..4c1c8a9 100644 --- a/apps/backend/queries/annunci.go +++ b/apps/backend/queries/annunci.go @@ -84,7 +84,10 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed) error { homepage = $44, url_immagini = $45, url_video = $46, - og_url = $48 + og_url = $48, + disponibile_da = $49, + permanenza = $50, + persone = $51 WHERE codice = $47 `, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore, annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il, @@ -97,7 +100,7 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed) error { annuncio.Numero_balconi, annuncio.Numero_terrazzi, annuncio.Numero_box, annuncio.Numero_postiauto, annuncio.Caratteristiche, annuncio.Accessori, annuncio.Titolo_it, annuncio.Desc_it, annuncio.Titolo_en, annuncio.Desc_en, annuncio.Stato, annuncio.Web, annuncio.Homepage, annuncio.Url_foto, - annuncio.Url_video, annuncio.Codice, annuncio.Og_url) + annuncio.Url_video, annuncio.Codice, annuncio.Og_url, annuncio.Disponibile_da, annuncio.Permanenza, annuncio.Persone) } else { batch.Queue(` @@ -149,9 +152,12 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed) error { url_immagini, url_video, codice, - og_url + og_url, + disponibile_da, + permanenza, + persone ) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51) `, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore, annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il, annuncio.Indirizzo, annuncio.Civico, annuncio.Comune, annuncio.Cap, @@ -163,7 +169,7 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed) error { annuncio.Numero_balconi, annuncio.Numero_terrazzi, annuncio.Numero_box, annuncio.Numero_postiauto, annuncio.Caratteristiche, annuncio.Accessori, annuncio.Titolo_it, annuncio.Desc_it, annuncio.Titolo_en, annuncio.Desc_en, annuncio.Stato, annuncio.Web, annuncio.Homepage, annuncio.Url_foto, - annuncio.Url_video, annuncio.Codice, annuncio.Og_url) + annuncio.Url_video, annuncio.Codice, annuncio.Og_url, annuncio.Disponibile_da, annuncio.Permanenza, annuncio.Persone) } } err = Db.Dbpool.SendBatch(Db.Ctx, batch).Close() diff --git a/apps/backend/typesdefs/models.go b/apps/backend/typesdefs/models.go index d3c7389..db59c28 100644 --- a/apps/backend/typesdefs/models.go +++ b/apps/backend/typesdefs/models.go @@ -261,7 +261,7 @@ type AnnuncioParsed struct { Url_video *[]string Web *bool Og_url *string - Disponibile_da *time.Time + Disponibile_da *string Permanenza *[]int Persone *[]string }