meesman #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: meesman | |
on: | |
schedule: | |
- cron: "0 15 * * 5" | |
workflow_dispatch: | |
jobs: | |
run: | |
runs-on: ubuntu-latest | |
env: | |
DataFolderName: ./data/meesman | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install required PowerShell modules | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
Install-Module UncommonSense.Hap, UncommonSense.Meesman, UncommonSense.Pushover -Scope CurrentUser | |
- name: Create data folder | |
shell: pwsh | |
run: | | |
if (-not (Test-Path -Path $env:DataFolderName -PathType Container)) | |
{ | |
New-Item -Path $env:DataFolderName -ItemType Directory | Out-Null | |
} | |
- name: Update fund data | |
shell: pwsh | |
run: | | |
$FundPriceData = Get-MeesmanFundPrice | |
$Date = $FundPriceData | Measure-Object -Property Date -Maximum | Select-Object -ExpandProperty Maximum | |
$DataFileName = "$(Get-Date -Date $Date -Format FileDate).xml" | |
$DataFilePath = Join-Path -Path $env:DataFolderName -ChildPath $DataFileName | |
$FundPriceData | Export-CliXml -Path $DataFilePath | |
- name: Clean-up data folder | |
shell: pwsh | |
run: | | |
Get-ChildItem -Path $env:DataFolderName | |
| Sort-Object Name -Descending | |
| Select-Object -Skip 3 | |
| Remove-Item -Force | |
- name: Send Pushover notification | |
env: | |
PUSHOVER_APP_MEESMAN: ${{secrets.PUSHOVER_APP_MEESMAN}} | |
PUSHOVER_USER_JUSTME: ${{secrets.PUSHOVER_USER_JUSTME}} | |
shell: pwsh | |
run: | | |
Get-ChildItem -Path $env:DataFolderName | |
| Import-CliXml | |
| Sort-Object -Property Fund, Date | |
| Group-Object -Property Fund | |
| Where-Object Name -eq 'Aandelen Wereldwijd Totaal' | |
| ForEach-Object { | |
$Body = | |
$_.Group | |
| ForEach-Object ` | |
-Begin { | |
$PreviousPrice = 0 | |
} ` | |
-Process { | |
$CurrentPrice = $_.Price | |
$PriceDiff = $CurrentPrice - $PreviousPrice | |
$FontStart, $FontStop, $Direction, $PriceDiffText = switch ($true) | |
{ | |
($PreviousPrice -eq 0) { '', '', '', ''; break } | |
($CurrentPrice -eq $PreviousPrice) { '', '', '', ''; break } | |
($CurrentPrice -gt $PreviousPrice) { '<font color="#090">', '</font>', ' ▲ ', ('€ {0}' -f $PriceDiff); break } | |
($CurrentPrice -lt $PreviousPrice) { '<font color="#900">', '</font>', ' ▼ ', ('€ {0}' -f $PriceDiff); break } | |
} | |
"$($_.Date.ToString('yyyy-MM-dd')): $($FontStart)$("€$($CurrentPrice)")$($Direction)$($PriceDiffText)$($FontStop)" | |
$PreviousPrice = $CurrentPrice | |
} | |
| Sort-Object -Descending {(++$script:Index)} | |
Send-PushoverNotification ` | |
-ApplicationToken $env:PUSHOVER_APP_MEESMAN ` | |
-Recipient $env:PUSHOVER_USER_JUSTME ` | |
-Title $_.Name ` | |
-Message ($Body -join "`n") ` | |
-Html | |
} | |
- name: Push changes to git repo | |
shell: bash | |
run: | | |
git config --global user.name 'Jan Hoek' | |
git config --global user.email 'github@uncommonsense.nl' | |
git remote set-url origin https://x-access-token:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}} | |
git pull | |
git add "$DataFolderName/*" | |
git commit -am 'Updated Meesman files' || echo "No changes to commit" | |
git push |