New-Item -Path "$home\Documents\WindowsPowerShell\Modules\CitiBike\Pages" -ItemType Directory -ErrorAction SilentlyContinue -Force | Out-Null
{ . $psScriptRoot\Find-BikeStation.ps1 } | Set-Content "$home\Documents\WindowsPowerShell\Modules\CitiBike\CitiBike.psm1"
{ @{ ModuleVersion = 0.1 ModuleToProcess = 'CitiBike.psm1' FormatsToProcess = 'CitiBike.Format.ps1xml' RequiredModules = 'Pipeworks' } } | Set-Content "$home\Documents\WindowsPowerShell\Modules\CitiBike\CitiBike.psd1"
{ @{ UseBootstrap = $true DomainSchematics = @{ "CitiBike.PowerShellPipeworks.com" = "Default" } WebCommand = @{ "Find-BikeStation" = @{ FriendlyName = "Find a Bike" } } } } | Set-Content "$home\Documents\WindowsPowerShell\Modules\CitiBike\CitiBike.Pipeworks.psd1"
$bikeStations.pstypenames.clear() $bikeStations.pstypenames.add('Citi.Bike.Station.List') $bikeStations
{ function Find-BikeStation { <# .Synopsis Finds bike stations .Description Finds CitiBank bike stations in New York #> param( # The Location Where You'd Like to Find a Bike [Parameter(Mandatory=$true,Position=0)] [string]$At = "" ) if (-not $script:CachedStationsAt) { $script:CachedStationsAt = [DateTime]::MinValue } $elapsed = [Datetime]::Now -$script:CachedStationsAt if ($elapsed.TotalMinutes -gt 10) { $script:CachedBikeStations = $null } if (-not $script:CachedBikeStations) { $bsi = Get-Web -Url "http://appservices.citibikenyc.com/data2/stations.php" -AsJson -UseWebRequest | Select-Object -ExpandProperty Results $script:CachedBikeStations = foreach ($bs in $bsi) { $parts = $bs.Label -split " " $newParts = foreach ($p in $parts) { if ($p -as [uint32]) { $lastDigit = $p.ToCharArray()[-1] if ($lastDigit -eq '1') { ($p + "st") } elseif ('2', '3' -contains $lastDigit) { ($p + "rd") } elseif ('4', '5', '6', '7', '8', '9','0' -contains $lastDigit) { ($p + "th") } } else { $p } } $bs | Add-Member NoteProperty Location "$($newParts -join ' ')" -Force -PassThru } } $stationList = $script:CachedBikeStations| Where-Object { $At -and $_.Location -like "*$At*" } $bikeStations = New-Object PSObject -Property @{ At = $At Stations = $stationList } $bikeStations.pstypenames.clear() $bikeStations.pstypenames.add('Citi.Bike.Station.List') $bikeStations } } | Set-Content "$home\Documents\WindowsPowerShell\Modules\CitiBike\Find-BikeStation.ps1"
$ezFormat= { $moduleName = 'CitiBike' $ModuleRoot = "$home\Documents\WindowsPowerShell\Modules\$moduleName" $formatting = @() $formatting += Write-FormatView -TypeName "Citi.Bike.Station.List" -Action { $data = $_ if ($request -and $response) { foreach ($Station in $data.Stations) { $l = New-Object PSObject -Property @{ Latitude = $station.Latitude Longitude = $station.Longitude StreetAddress = $Station.Location Locality = " " } $l.pstypenames.clear() $l.pstypenames.add('http://schema.org/Place') "<h2> $($Station.Label) </h2> <h3 class='span4'> $($Station.AvailableBikes) <span style='vertical-alignment:middle;font-size:.66em'> Available Bikes </span> </h3> <h3 class='span4'> $($Station.AvailableDocks) <span style='vertical-alignment:middle;font-size:.66em'> Available Docks </span> </h3> <div class='span6 offset2'> $($l |Out-HTML) </div> <div class='span9'> </div> <hr style='line-height:200%;clear:both' /> " } } else { $data.Stations | Select * | Out-String -Width 10kb } } $formatting | Out-FormatData | Set-Content "$moduleRoot\$ModuleName.Format.ps1xml" } & $ezFormat $ezFormat | Set-Content "$home\Documents\WindowsPowerShell\Modules\CitiBike\CitiBike.Ezformat.ps1"