Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-22 09:35:12 +02:00
committed by GitHub
parent 87afacd48d
commit 052eef4657
+41 -18
View File
@@ -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
}
}