-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvert-ToIcs.ps1
98 lines (92 loc) · 2.86 KB
/
Convert-ToIcs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function Get-Calendar {
[CmdletBinding()]
param (
[PSCustomObject[]]$events,
$interest,
$team=""
)
$vCalendar = @"
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
X-WR-CALNAME:Sloeproeiwedstrijden-2024
PRODID:-//DevOps1//RPU-IcsGenerator-0.1//EN
"@
foreach ($event in $events) {
$evDateParts = $event.date.split("-")
if ($interest){
$evDescription = "?-M2-?-{0}-?" -f $event.description.ToUpper()
}
elseif ($team -ne ""){
$evDescription = "{1}-{0}" -f $event.description, $team
}
else{
$evDescription = $event.description
}
$parm = @{
eventDate = Get-Date -Year $evDateParts[2] -Month $evDateParts[1] -Day $evDateParts[0]
eventDescription = $evDescription
eventSummary = $event.summary
eventLocation = $event.location
}
$vCalendar += Get-Event @parm
}
$vCalendar += @"
END:VCALENDAR
"@
return $vCalendar
}
function Get-MD5Hash {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$input
)
$stringAsStream = [System.IO.MemoryStream]::new()
$writer = [System.IO.StreamWriter]::new($stringAsStream)
$writer.Write($input)
$writer.Flush()
$stringAsStream.Position = 0
$md5Hash = Get-FileHash -InputStream $stringAsStream | Select-Object -ExpandProperty Hash
return $md5Hash
}
function Get-Event {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[datetime]$eventDate,
$eventDescription,
$eventSummary,
$eventLocation
)
# $eventGuid = [guid]::NewGuid()
# make sure the same 'guid' is generated for the same event
$md5Hash = Get-MD5Hash -input ("{0:yyyyMMdd}{1}{2}" -f $eventDate, $eventDescription, $eventLocation)
$eventGuid = "{0}-{1}-{2}-{3}-{4}" -f $md5Hash.Substring(0,8), $md5Hash.Substring(8,4), $md5Hash.Substring(12,4), $md5Hash.Substring(16,4), $md5hash.Substring(20)
$now = Get-Date
$eventStart = Get-Date $eventDate -Hour 5 -Minute 30
$eventEnd = Get-Date $eventDate -Hour 16 -Minute 30
$vEvent = @"
BEGIN:VEVENT
UID:{0}
CREATED:{1:yyyyMMddTHHmmssZ}
DTSTAMP:{1:yyyyMMddTHHmmssZ}
LAST-MODIFIED:{1:yyyyMMddTHHmmssZ}
SEQUENCE:0
SUMMARY;LANGUAGE=nl-nl:{3}
DTSTART:{6:yyyyMMddTHHmmssZ}
DTEND:{7:yyyyMMddTHHmmssZ}
DESCRIPTION:{4}
LOCATION:{5}
TRANSP:OPAQUE
END:VEVENT
"@ -f $eventGuid, $now, $eventDate, $eventDescription, $eventSummary, $eventLocation, $eventStart, $eventEnd
return $vEvent
}
$interest = $false
$team = "Mix2"
$file = Join-Path -Path $PSScriptRoot -ChildPath "2024-wedstrijden.csv"
$events = Get-Content -Path $file -raw | ConvertFrom-Csv
$events | Format-Table
$ics = Join-Path -Path $PSScriptRoot -ChildPath "calendar.ics"
Get-Calendar -events $events -interest $interest -team $team| out-file $ics