mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
Add files via upload
This commit is contained in:
+47
-24
@@ -20,7 +20,7 @@ type Contact struct {
|
|||||||
Position string `json:"position"`
|
Position string `json:"position"`
|
||||||
Phone string `json:"phone,omitempty"`
|
Phone string `json:"phone,omitempty"`
|
||||||
ServicePhone string `json:"service_phone,omitempty"`
|
ServicePhone string `json:"service_phone,omitempty"`
|
||||||
Table int `json:"table"`
|
Table int `json:"table"` // 1 for first table, 2 for second table
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContactData struct {
|
type ContactData struct {
|
||||||
@@ -32,7 +32,7 @@ type ContactData struct {
|
|||||||
var (
|
var (
|
||||||
currentData *ContactData
|
currentData *ContactData
|
||||||
dataFile = "data/contacts.json"
|
dataFile = "data/contacts.json"
|
||||||
xlsxFile = "TelefonniSeznamWeb.xlsx"
|
xlsxFile = "contacts.xlsx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func startAutoReload() {
|
func startAutoReload() {
|
||||||
@@ -193,15 +193,20 @@ func parseExcelFile(filename string) ([]Contact, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sheetName := sheets[0]
|
sheetName := sheets[0]
|
||||||
|
var contacts []Contact
|
||||||
|
|
||||||
// Parse single table (A-E columns)
|
// Parse first table (A-D columns)
|
||||||
contacts := parseTable(f, sheetName, "A", "E", 1)
|
contacts = append(contacts, parseTable(f, sheetName, "A", "D", 1)...)
|
||||||
|
|
||||||
|
// Parse second table (F-H columns)
|
||||||
|
contacts = append(contacts, parseTable(f, sheetName, "F", "H", 2)...)
|
||||||
|
|
||||||
return contacts, nil
|
return contacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum int) []Contact {
|
func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum int) []Contact {
|
||||||
var contacts []Contact
|
var contacts []Contact
|
||||||
|
var currentContact *Contact
|
||||||
|
|
||||||
// Get all rows in the sheet
|
// Get all rows in the sheet
|
||||||
rows, err := f.GetRows(sheetName)
|
rows, err := f.GetRows(sheetName)
|
||||||
@@ -210,14 +215,19 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum i
|
|||||||
return contacts
|
return contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip header rows (first row is header)
|
// Skip header rows (first 3 rows based on your description)
|
||||||
startRow := 1
|
startRow := 3
|
||||||
if len(rows) <= startRow {
|
if len(rows) <= startRow {
|
||||||
return contacts
|
return contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Column indices (A-E: name, position, phone, service_phone, extension)
|
// Column indices
|
||||||
nameCol, positionCol, phoneCol, servicePhoneCol, extensionCol := 0, 1, 2, 3, 4
|
var nameCol, positionCol, phoneCol, servicePhoneCol int
|
||||||
|
if tableNum == 1 {
|
||||||
|
nameCol, positionCol, phoneCol, servicePhoneCol = 0, 1, 2, 3 // A, B, C, D
|
||||||
|
} else {
|
||||||
|
nameCol, positionCol, phoneCol = 5, 6, 7 // F, G, H
|
||||||
|
}
|
||||||
|
|
||||||
for i := startRow; i < len(rows); i++ {
|
for i := startRow; i < len(rows); i++ {
|
||||||
row := rows[i]
|
row := rows[i]
|
||||||
@@ -227,11 +237,20 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum i
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for "Aktualizace" - end of data
|
||||||
|
if len(row) > nameCol && strings.Contains(strings.ToLower(row[nameCol]), "aktualizace") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for special formatting rows (like "*02(xx)")
|
||||||
|
if len(row) > positionCol && strings.Contains(row[positionCol], "*") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
name := strings.TrimSpace(row[nameCol])
|
name := strings.TrimSpace(row[nameCol])
|
||||||
position := ""
|
position := ""
|
||||||
phone := ""
|
phone := ""
|
||||||
servicePhone := ""
|
servicePhone := ""
|
||||||
extension := ""
|
|
||||||
|
|
||||||
if len(row) > positionCol {
|
if len(row) > positionCol {
|
||||||
position = strings.TrimSpace(row[positionCol])
|
position = strings.TrimSpace(row[positionCol])
|
||||||
@@ -239,33 +258,37 @@ func parseTable(f *excelize.File, sheetName, startCol, endCol string, tableNum i
|
|||||||
if len(row) > phoneCol {
|
if len(row) > phoneCol {
|
||||||
phone = strings.TrimSpace(row[phoneCol])
|
phone = strings.TrimSpace(row[phoneCol])
|
||||||
}
|
}
|
||||||
if len(row) > servicePhoneCol {
|
if tableNum == 1 && len(row) > servicePhoneCol {
|
||||||
servicePhone = strings.TrimSpace(row[servicePhoneCol])
|
servicePhone = strings.TrimSpace(row[servicePhoneCol])
|
||||||
}
|
}
|
||||||
if len(row) > extensionCol {
|
|
||||||
extension = strings.TrimSpace(row[extensionCol])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean phone numbers
|
// Clean phone numbers
|
||||||
phone = cleanPhoneNumber(phone)
|
phone = cleanPhoneNumber(phone)
|
||||||
servicePhone = cleanPhoneNumber(servicePhone)
|
servicePhone = cleanPhoneNumber(servicePhone)
|
||||||
|
|
||||||
// Combine extension with service phone if both exist
|
// If we have a name, start a new contact
|
||||||
if servicePhone != "" && extension != "" {
|
if name != "" && !strings.Contains(name, "(") {
|
||||||
servicePhone = fmt.Sprintf("%s (%s)", servicePhone, extension)
|
currentContact = &Contact{
|
||||||
} else if extension != "" {
|
|
||||||
servicePhone = extension
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have a name, create new contact
|
|
||||||
if name != "" {
|
|
||||||
contacts = append(contacts, Contact{
|
|
||||||
Name: name,
|
Name: name,
|
||||||
Position: position,
|
Position: position,
|
||||||
Phone: phone,
|
Phone: phone,
|
||||||
ServicePhone: servicePhone,
|
ServicePhone: servicePhone,
|
||||||
Table: tableNum,
|
Table: tableNum,
|
||||||
})
|
}
|
||||||
|
contacts = append(contacts, *currentContact)
|
||||||
|
} else if currentContact != nil {
|
||||||
|
// This is additional data for the current contact
|
||||||
|
newContact := *currentContact
|
||||||
|
if position != "" {
|
||||||
|
newContact.Position = position
|
||||||
|
}
|
||||||
|
if phone != "" {
|
||||||
|
newContact.Phone = phone
|
||||||
|
}
|
||||||
|
if servicePhone != "" {
|
||||||
|
newContact.ServicePhone = servicePhone
|
||||||
|
}
|
||||||
|
contacts = append(contacts, newContact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user