Skip to content

Instantly share code, notes, and snippets.

@erikusaj
Created February 13, 2013 08:36
Show Gist options
  • Save erikusaj/4943113 to your computer and use it in GitHub Desktop.
Save erikusaj/4943113 to your computer and use it in GitHub Desktop.
LJSE stock ticker pre-formatting With PowerShell
$file = "ljse.txt"
$namefix = @(("NALOZBE", "NALOŽBE"), ("PORTOROZ","PORTOROŽ"), ("LASKO","LAŠKO"), ("CATEZ","ČATEŽ"), ("ZITO", "ŽITO"))
$ft = "{2}"
$eq = "{14}l{2}"
$lt = "{15}î{2}"
$gt = "{16}ì{2}"
Try
{
$stockindex=invoke-RestMethod -Uri "http://sourceserver/getStockIndexList" -Method Get
$stocklist=invoke-RestMethod -Uri "http://sourceserver/getStockList" -Method Get
foreach($i in $stocklist.stockPlanet9Response) {
$i.lastChangePercentage = "{0:N2}" -f [System.Math]::Round($i.lastChangePercentage,2)
$i.closePrice = "{0:N2}" -f [System.Math]::Round($i.closePrice,2)
foreach($j in $namefix) {
$i.description = $i.description -replace $j[0], $j[1]
}
}
$out = New-Object PSObject -Property @{
description=$stockindex.stockIndexPlanet9Response.name; closePrice="{0:N2}" -f [System.Math]::Round($stockindex.stockIndexPlanet9Response.value,2);
lastchangePercentage="{0:N2}" -f [System.Math]::Round($stockindex.stockIndexPlanet9Response.changePercent,2);
}
$buff = ""
foreach($i in $out)
{
$sym = ""
if ([Double]$i.lastchangePercentage -eq 0) {$sym = $eq}
elseif ([Double]$i.lastchangePercentage -lt 0) {$sym = $lt}
elseif ([Double]$i.lastchangePercentage -gt 0) {$sym = $gt}
$buff += $i.description + " " + $i.closePrice + " "+ $sym + " " + $i.lastchangePercentage + " // `r`n"
}
$out = $stocklist.stockPlanet9Response | Sort-Object description | Select-Object description,closePrice,lastChangePercentage
foreach($i in $out)
{
$sym = ""
if ([Double]$i.lastchangePercentage -eq 0) {$sym = $eq}
elseif ([Double]$i.lastchangePercentage -lt 0) {$sym = $lt}
elseif ([Double]$i.lastchangePercentage -gt 0) {$sym = $gt}
$buff += $i.description + " " + $i.closePrice + " "+ $sym + " " + $i.lastchangePercentage + " // `r`n"
}
$buff | Out-File $file -encoding "unicode"
}
Catch [system.exception]
{
"system exception"
$out = "" | Out-File $file -encoding "unicode"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment