fix: update data extraction and parsing for availability, permanence, and people in Annuncio
This commit is contained in:
parent
19d273ff49
commit
9fb9623671
4 changed files with 28 additions and 9 deletions
|
|
@ -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{}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue