Skip to content

Commit 31a08b9

Browse files
committedDec 10, 2022
sqlbits schedule
1 parent 47f82bd commit 31a08b9

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed
 

‎Get-SQLBitsSchedule.ps1

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
function Get-SQLBitsSchedule {
2+
[CmdletBinding()]
3+
param (
4+
# [Parameter()]
5+
# [ValidateSet('All', 'Schedule', 'Sessions', 'Speakers')]
6+
# $filter = 'Schedule',
7+
# # How do you want it?
8+
[Parameter()]
9+
[ValidateSet('Raw', 'Excel')]
10+
$Output = 'Raw'
11+
)
12+
13+
$BaseUri = 'https://sessionize.com/api/v2/u1qovn3p/view'
14+
$filter = 'Schedule'
15+
switch ($filter) {
16+
'All' {
17+
$uri = '{0}/All' -f $BaseUri
18+
}
19+
'Schedule' {
20+
$uri = '{0}/All' -f $BaseUri
21+
}
22+
'Sessions' {
23+
$uri = '{0}/sessions' -f $BaseUri
24+
}
25+
'Speakers' {
26+
$uri = '{0}/speakers' -f $BaseUri
27+
}
28+
Default {
29+
$uri = '{0}/All' -f $BaseUri
30+
}
31+
}
32+
33+
$Data = Invoke-RestMethod -Uri $uri
34+
35+
switch ($output) {
36+
'Raw' {
37+
$Data
38+
}
39+
'Excel' {
40+
if (Get-Module -Name ImportExcel -ErrorAction SilentlyContinue -ListAvailable) {
41+
if ($filter -eq 'Schedule') {
42+
$rooms = ($data.rooms | Sort-Object name)
43+
$Speakers = $data.speakers
44+
# Thank you Shane - https://nocolumnname.blog/2020/10/29/pivot-in-powershell/
45+
$props = @(
46+
@{ Name = 'Day' ; Expression = { $Psitem.Group[0].startsAt.DayOfWeek } }
47+
@{ Name = 'Date' ; Expression = { $Psitem.Group[0].startsAt.tolongdatestring() } }
48+
@{ Name = 'StartTime' ; Expression = { $Psitem.Group[0].startsAt.ToShortTimeString() } }
49+
@{ Name = 'EndTime' ; Expression = { $Psitem.Group[0].EndsAt.ToShortTimeString() } }
50+
foreach ($room in $rooms) {
51+
$rn = $room.Name
52+
@{
53+
Name = $rn
54+
Expression = {
55+
'{0}
56+
{1}' -f @(
57+
($Psitem.Group | Where-Object { $PSItem.roomID -eq $room.id }).title,
58+
(($Psitem.Group | Where-Object { $PSItem.roomID -eq $room.id }).Speakers.ForEach{ $Speakers | Where-Object id -eq $_ }.FullName -join ' ')
59+
)
60+
61+
}.GetNewClosure()
62+
}
63+
}
64+
)
65+
$Date = Get-Date -Format 'yyyy-MM-dd-HH-mm-ss'
66+
$FilePath = '{0}\SQLBitsSchedule{1}_{2}.xlsx' -f $env:TEMP, $filter, $Date
67+
68+
$sessions = $Data.sessions | Group-Object -Property StartsAt | Select-Object $props
69+
70+
$sessions | Group-Object Day | ForEach-Object{
71+
72+
$worksheetName = $_.Name
73+
$excel = $_.Group | Export-Excel -Path $FilePath -WorksheetName $worksheetName -AutoSize -FreezePane 2,5 -PassThru
74+
1..15 | ForEach-Object {
75+
Set-ExcelRow -ExcelPackage $excel -WorksheetName $worksheetName -Row $_ -Height 30 -WrapText
76+
}
77+
78+
79+
$rulesparam = @{
80+
Address = $excel.Workbook.Worksheets[$WorkSheetName].Dimension.Address
81+
WorkSheet = $excel.Workbook.Worksheets[$WorkSheetName]
82+
RuleType = 'Expression'
83+
}
84+
85+
Add-ConditionalFormatting @rulesparam -ConditionValue '"Break",$E1)))' -BackgroundColor PaleGreen -StopIfTrue
86+
Add-ConditionalFormatting @rulesparam -ConditionValue 'NOT(ISERROR(FIND("Keynote",$E1)))' -BackgroundColor BlueViolet -StopIfTrue
87+
Add-ConditionalFormatting @rulesparam -ConditionValue 'NOT(ISERROR(FIND("Lunch",$E1)))' -BackgroundColor Chocolate
88+
Add-ConditionalFormatting @rulesparam -ConditionValue 'NOT(ISERROR(FIND("Prize",$E1)))' -BackgroundColor PowderBlue
89+
Add-ConditionalFormatting @rulesparam -ConditionValue 'NOT(ISERROR(FIND("Free",$E1)))' -BackgroundColor GoldenRod
90+
Add-ConditionalFormatting @rulesparam -ConditionValue 'NOT(ISERROR(FIND("Registration",$E1)))' -BackgroundColor DarkOrange
91+
92+
Close-ExcelPackage $excel
93+
}
94+
Invoke-Item $filepath
95+
}
96+
97+
} else {
98+
Write-Warning 'You need to install ImportExcel to use this option but here is a CSV instead'
99+
$Data | Export-Csv -Path .\SQLBitsSchedule.csv -NoTypeInformation
100+
}
101+
102+
}
103+
Default {
104+
105+
}
106+
}
107+
}
108+
Get-SQLBitsSchedule -Output Excel
109+
<#
110+
foreach ($day in $data[2]){
111+
$Date = '{0} {1}' -f $day.date.DayOfWeek, $day.date.ToLongDateString()
112+
$Schedule = ''
113+
114+
}
115+
116+
($data.sessions | Group-Object startsat)[0]
117+
v
118+
119+
120+
$SortedSessions = foreach ($time in ($data.sessions | Group-Object startsat).Group){
121+
$room = $data.rooms.where{$PsItem.id -eq $time.roomid}.name
122+
[PSCustomObject]@{
123+
startsat = $time.startsat
124+
endsat = $time.endsat
125+
126+
$room = $time.title
127+
}
128+
}
129+
$SortedSessions | Export-Excel -Path c:\temp\sess.xlsx -Show
130+
#>

0 commit comments

Comments
 (0)
Please sign in to comment.