Skip to content

Commit

Permalink
fix add calendar title
Browse files Browse the repository at this point in the history
  • Loading branch information
loan-mgt committed Sep 5, 2024
1 parent 9b24a18 commit 2a1cd13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
environment:
- MYCPE_USERNAME=${MYCPE_USERNAME}
- MYCPE_PASSWORD=${MYCPE_PASSWORD}
- START_TIMESTAMP=${START_TIMESTAMP}
- END_TIMESTAMP=${END_TIMESTAMP}

nginx:
image: ghcr.io/loan-mgt/10m-caching:latest
Expand Down
7 changes: 5 additions & 2 deletions ical/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
const regexPattern = `(?P<location>.*?)(?P<promo>[1-9][A-Z]{3,})(?P<summary>.*?)(?P<description>(( |n)[A-Z]{3,} .*)|$)`

// GenerateICS generates an ICS string from a list of events
func GenerateICS(events []Event) string {
ics := "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Your Organization//Your Product//EN\n"
func GenerateICS(events []Event, calendarName string) string {
ics := "BEGIN:VCALENDAR\n"
ics += "VERSION:2.0\n"
ics += "PRODID:-//Your Organization//Your Product//EN\n"
ics += fmt.Sprintf("X-WR-CALNAME:%s\n", calendarName) // Set calendar name

// Define the layout for parsing the datetime with a timezone offset
const layout = "2006-01-02T15:04:05-0700"
Expand Down
25 changes: 17 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import (
"cpe/calendar/request"
"log"
"net/http"
"os"

"github.com/gorilla/mux"
"github.com/joho/godotenv"
)

func init() {
// Load environment variables from .env file
if err := godotenv.Load(); err != nil {
log.Fatalf("Error loading .env file: %v", err)
}
}

func main() {
r := mux.NewRouter()

Expand All @@ -23,10 +32,10 @@ func main() {
}

// generateICSHandler generates the ICS file and sends it in the response with a given filename
func generateICSHandler(w http.ResponseWriter, _ *http.Request, filename string) {
// Set start and end times (these could be retrieved from request parameters if needed)
start := "1725228000000" // Example start timestamp
end := "1728684000000" // Example end timestamp
func generateICSHandler(w http.ResponseWriter, _ *http.Request, filename, calendarName string) {
// Get start and end times from environment variables
start := os.Getenv("START_TIMESTAMP")
end := os.Getenv("END_TIMESTAMP")

// Step 1: Fetch data from the source using the updated FetchData function
data, err := request.FetchData(start, end)
Expand All @@ -46,8 +55,8 @@ func generateICSHandler(w http.ResponseWriter, _ *http.Request, filename string)
return
}

// Step 3: Generate the iCal file
icsContent := ical.GenerateICS(events)
// Step 3: Generate the iCal file with the calendar name
icsContent := ical.GenerateICS(events, calendarName)

// Step 4: Set headers for the iCal file response with the provided filename
w.Header().Set("Content-Type", "text/calendar")
Expand All @@ -59,6 +68,6 @@ func generateICSHandler(w http.ResponseWriter, _ *http.Request, filename string)

// generate3IRCHandler is a wrapper around generateICSHandler that uses a specific filename
func generate3IRCHandler(w http.ResponseWriter, r *http.Request) {
// Call generateICSHandler with the specific filename
generateICSHandler(w, r, "3irc_calendar.ics")
// Call generateICSHandler with the specific filename and calendar name
generateICSHandler(w, r, "3irc_calendar.ics", "3IRC Calendar")
}

0 comments on commit 2a1cd13

Please sign in to comment.