-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (88 loc) · 3.56 KB
/
meewind.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: meewind
on:
schedule:
- cron: "5 12 * * 5"
# push:
# branches:
# - "master"
workflow_dispatch:
jobs:
run:
runs-on: ubuntu-latest
env:
DataFolderName: ./data/meewind
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Install required PowerShell modules
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module UncommonSense.Hap, UncommonSense.Meewind, 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: |
$DataFileName = "$(Get-Date -Format FileDate).xml"
$DataFilePath = Join-Path -Path $env:DataFolderName -ChildPath $DataFileName
Get-MeewindFundPrice | 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: Push changes to git repo
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 add ./data/meewind/*
git commit -am 'Updated meewind files' || echo "No changes to commit"
git push
- name: Send notification
shell: pwsh
env:
PUSHOVER_APP_MEEWIND: ${{ secrets.PUSHOVER_APP_MEEWIND}}
PUSHOVER_USER_JUSTME: ${{secrets.PUSHOVER_USER_JUSTME}}
run: |
Get-ChildItem -Path $env:DataFolderName
| Import-CliXml
| Sort-Object -Property Fund, Date
| Group-Object -Property Fund
| ForEach-Object {
$Message =
$_.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)}
| Join-String -Separator '<br/>'
Send-PushoverNotification `
-ApplicationToken "$env:PUSHOVER_APP_MEEWIND" `
-Recipient "$env:PUSHOVER_USER_JUSTME" `
-Title "Meewind $($_.Name)" `
-Message $Message `
-Html
}