From 052eef4657ce8900b61c4569f4f9c33878f26a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dvo=C5=99=C3=A1k?= <150935816+Dvorinka@users.noreply.github.com> Date: Thu, 22 May 2025 09:35:12 +0200 Subject: [PATCH] Add files via upload --- contact-scrape-test/contact-scrape.go | 59 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/contact-scrape-test/contact-scrape.go b/contact-scrape-test/contact-scrape.go index 6f803e9..2da9315 100644 --- a/contact-scrape-test/contact-scrape.go +++ b/contact-scrape-test/contact-scrape.go @@ -187,6 +187,7 @@ func parseExcelFile(filename string) ([]Contact, error) { func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum int) []Contact { var contacts []Contact var currentContact *Contact + var lastUpdate string // Get all rows in the sheet rows, err := f.GetRows(sheetName) @@ -217,13 +218,11 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum i continue } - // Skip general contacts and update date line - if strings.Contains(row[nameCol], "převzetí hovoru") || - strings.Contains(row[nameCol], "hlavní vchod") || - strings.Contains(row[nameCol], "brána") || - strings.HasPrefix(row[nameCol], "Aktualizace dne") || - strings.HasPrefix(row[nameCol], "Poslední aktualizace") { - continue + // Check for "Aktualizace" - end of data + if len(row) > nameCol && strings.Contains(strings.ToLower(row[nameCol]), "aktualizace") { + lastUpdate = row[nameCol] + currentContact = nil // Reset to avoid attaching to previous contact + break } // Check for special formatting rows (like "*02(xx)") @@ -260,19 +259,43 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum i Table: tableNum, } contacts = append(contacts, *currentContact) - } else if currentContact != nil && !strings.HasPrefix(row[nameCol], "Aktualizace dne") { - // This is additional data for the current contact - newContact := *currentContact - if position != "" { + } else if strings.Contains(name, "Aktualizace") { + // Capture the update date + lastUpdate = name + currentContact = nil // Reset to avoid attaching to previous contact + } else if currentContact != nil && name == "" { + // This is additional data for the current contact or a general contact + if position != "" && !strings.Contains(position, "Vorlová") && !strings.Contains(position, "inženýrka") { + // Treat as a general contact if it doesn't contain specific personal identifiers + currentContact = &Contact{ + Name: position, // Use position as the name for general contacts + Position: "", + Phone: phone, + ServicePhone: servicePhone, + Table: tableNum, + } + contacts = append(contacts, *currentContact) + } else if position != "" { + newContact := *currentContact newContact.Position = position + if phone != "" { + newContact.Phone = phone + } + if servicePhone != "" { + newContact.ServicePhone = servicePhone + } + contacts = append(contacts, newContact) } - if phone != "" { - newContact.Phone = phone - } - if servicePhone != "" { - newContact.ServicePhone = servicePhone - } - contacts = append(contacts, newContact) + } + } + + // Update last updated date + if lastUpdate != "" { + lastUpdated, err := time.Parse("2.1.2006", lastUpdate) + if err != nil { + log.Printf("Error parsing last updated date: %v", err) + } else { + currentData.LastUpdated = lastUpdated } }