Skip to content

Instantly share code, notes, and snippets.

@lwsrbrts
Last active February 19, 2024 16:17
Show Gist options
  • Save lwsrbrts/d96092b65f2f7b7952e2f7983a9ee527 to your computer and use it in GitHub Desktop.
Save lwsrbrts/d96092b65f2f7b7952e2f7983a9ee527 to your computer and use it in GitHub Desktop.
Used to obtain the average natural gas calorific value for UK North West region from a set date to now.
$TodayDate = Get-Date -Format "yyyy-MM-dd"
$PreviousReading = Read-Host -Prompt 'Enter the date of the previous reading in dd/mm/yyyy format'
$PreviousReadingDate = Get-Date $PreviousReading -Format "yyyy-MM-dd"
$Soap = @"
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetPublicationDataWM xmlns="http://www.NationalGrid.com/MIPI/">
<reqObject>
<LatestFlag>Latest</LatestFlag>
<ApplicableForFlag>ApplicableFor</ApplicableForFlag>
<FromDate>$($PreviousReadingDate)T00:00:00.000Z</FromDate>
<ToDate>$($TodayDate)T00:00:00.000Z</ToDate>
<DateType>GASDAY</DateType>
<PublicationObjectNameList>
<string>Calorific Value, LDZ(NW)</string>
</PublicationObjectNameList>
</reqObject>
</GetPublicationDataWM>
</soap12:Body>
</soap12:Envelope>
"@
$Req = Invoke-WebRequest -Uri "http://mip-prodpull-api.azurewebsites.net/MIPIws-public/Public/PublicWebService.asmx" -Method 'Post' -ContentType 'application/soap+xml' -Body $Soap
#Set-Content -Path D:\test.xml -Value $Req.Content # If you'd like to save the output to disk?
[xml]$XML = $Req
$Value = $XML.Envelope.Body.GetPublicationDataWMResponse.GetPublicationDataWMResult.CLSMIPIPublicationObjectBE.PublicationObjectData.CLSPublicationObjectDataBE.Value | Measure-Object -Average
$Value.Average
[math]::Round($Value.Average, 4)
#OR
"{0:N2}" -f $Value.Average
@1CM69
Copy link

1CM69 commented Oct 30, 2023

Thanks for your additions and comments. Always very helpful.

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment