mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 12:32:59 +00:00
Add files via upload
This commit is contained in:
+4
-4
@@ -95,7 +95,7 @@ monitor: ## Monitor the service with file watching
|
|||||||
@while true; do \
|
@while true; do \
|
||||||
inotifywait -e modify contacts.xlsx 2>/dev/null && \
|
inotifywait -e modify contacts.xlsx 2>/dev/null && \
|
||||||
echo "File changed, reloading..." && \
|
echo "File changed, reloading..." && \
|
||||||
curl -X POST http://localhost:$(PORT)/reload; \
|
curl -X POST http://localhost:$(PORT)/kontakt/reload; \
|
||||||
sleep 1; \
|
sleep 1; \
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -136,6 +136,6 @@ info: ## Show application information
|
|||||||
@echo "Build dir: $(BUILD_DIR)"
|
@echo "Build dir: $(BUILD_DIR)"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Endpoints:"
|
@echo "Endpoints:"
|
||||||
@echo " http://localhost:$(PORT)/ - Web interface"
|
@echo " http://localhost:$(PORT)/kontakt - Web interface"
|
||||||
@echo " http://localhost:$(PORT)/contacts - JSON API"
|
@echo " http://localhost:$(PORT)/kontakt/contacts - JSON API"
|
||||||
@echo " http://localhost:$(PORT)/reload - Reload data (POST)"
|
@echo " http://localhost:$(PORT)/kontakt/reload - Reload data (POST)"
|
||||||
@@ -35,12 +35,32 @@ var (
|
|||||||
xlsxFile = "contacts.xlsx"
|
xlsxFile = "contacts.xlsx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func startAutoReload() {
|
||||||
|
ticker := time.NewTicker(3 * 24 * time.Hour)
|
||||||
|
quit := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
log.Println("Auto-reloading contact data...")
|
||||||
|
loadData()
|
||||||
|
case <-quit:
|
||||||
|
ticker.Stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Create data directory if it doesn't exist
|
// Create data directory if it doesn't exist
|
||||||
if err := os.MkdirAll("data", 0755); err != nil {
|
if err := os.MkdirAll("data", 0755); err != nil {
|
||||||
log.Printf("Warning: Could not create data directory: %v", err)
|
log.Printf("Warning: Could not create data directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start auto-reload scheduler
|
||||||
|
startAutoReload()
|
||||||
|
|
||||||
// Load existing data or parse from Excel
|
// Load existing data or parse from Excel
|
||||||
loadData()
|
loadData()
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,7 @@ type GeoCoords struct {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
logFile, err := os.OpenFile("server.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
||||||
if err == nil {
|
|
||||||
log.SetOutput(io.MultiWriter(os.Stdout, logFile))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server setup
|
|
||||||
http.HandleFunc("/submit", enableCORS(handleSubmit))
|
http.HandleFunc("/submit", enableCORS(handleSubmit))
|
||||||
http.HandleFunc("/health", enableCORS(func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/health", enableCORS(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@@ -57,12 +52,12 @@ func main() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
http.HandleFunc("/kontakt", enableCORS(func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/kontakt", enableCORS(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Check if service is running
|
// Run make dev in the kontakt directory
|
||||||
cmd := exec.Command("systemctl", "is-active", "contact-scrape")
|
cmd := exec.Command("make", "dev")
|
||||||
err := cmd.Run()
|
cmd.Dir = "kontakt"
|
||||||
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Kontakt service not running - please run in new terminal:")
|
log.Printf("Error running make dev: %v", err)
|
||||||
log.Printf("cd kontakt && sudo make dev")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
http.ServeFile(w, r, "kontakt/index.html")
|
http.ServeFile(w, r, "kontakt/index.html")
|
||||||
@@ -74,8 +69,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Server běží na portu %s", port)
|
log.Printf("Server běží na portu %s", port)
|
||||||
log.Printf("Logs are being written to server.log")
|
err := http.ListenAndServe(":"+port, nil)
|
||||||
err = http.ListenAndServe(":"+port, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Chyba při spuštění serveru: %v", err)
|
log.Fatalf("Chyba při spuštění serveru: %v", err)
|
||||||
}
|
}
|
||||||
@@ -176,11 +170,11 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error {
|
func sendEmail(entry TripEntry, parsedDateStart, parsedDateEnd time.Time, czechMonths []string) error {
|
||||||
smtpHost := "smtp.gmail.com"
|
smtpHost := "mail.pp-kunovice.cz"
|
||||||
smtpPort := 465
|
smtpPort := 465
|
||||||
sender := "contact.dvorak@gmail.com"
|
sender := "sluzebnicek@pp-kunovice.cz"
|
||||||
password := "pnhkcsahbwsbpyqj"
|
password := "7g}qznB5bj"
|
||||||
recipient := "contact.dvorak@gmail.com"
|
recipient := "sluzebnicek@pp-kunovice.cz"
|
||||||
|
|
||||||
m := gomail.NewMessage()
|
m := gomail.NewMessage()
|
||||||
m.SetHeader("From", sender)
|
m.SetHeader("From", sender)
|
||||||
|
|||||||
Reference in New Issue
Block a user