-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-daily-quebecir.ps1
69 lines (59 loc) · 2.92 KB
/
send-daily-quebecir.ps1
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
$Telegramtoken = "6258988051:AAFoX0IN3XZDUc-OLt7w3V7hj9dVu0tHRsU"
$OpenAIToken = "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"
if (!(Test-Path -Path "Data"))
{
mkdir Data
}
# ..\Supabase-Module\Supabase.ps1
. .\TL-Base.ps1
function send-currency {
param (
$currency,
$chatid,
$Telegramtoken
)
$file=Get-ChildItem -Path .\Data\navasan.json
if ($file.LastWriteTime.DayOfYear -eq $(Get-Date).DayOfYear) {
<# Action to perform if the condition is true #>
$navasan=Get-Content -Path .\Data\navasan.json | ConvertFrom-Json -AsHashtable
}
else {
<# Action when all if and elseif conditions are false #>
$rates=Invoke-RestMethod -Uri "http://api.navasan.tech/latest/?api_key=freeKDZGcDTlul0hAApHujULqvN3Lixf"
$rates | Out-File -FilePath "./Data/navasan.json"
$navasan=$rates | ConvertFrom-Json -AsHashtable
}
# $cads=$navasan.GetEnumerator() | Where-Object {$_ -like "cad"}
# $content = "Cad to IRR :$($navasan.cad.value)`nDate: $($navasan.cad.date)"
$content = "قیمت امروز دلار کانادا :$($navasan.cad.value)تومان `nتاریخ: $($navasan.cad.date)`n<a href='https://fa.navasan.net/havale_canada.php'>مرجع سایت نوسان</a> "
Send-TelegramTextMessage -BotToken $Telegramtoken -ChatID $chatid -Message $content -ParseMode HTML #-1001942280822
# Send-Telegram -ChatId 95589475 -Message $content
# $data=Get-Supabase -table "data"
# $data= $data | ConvertFrom-Json -AsHashtable
# Add-Supabase -table "data" -data @{"id"=$data.id.Length+1;"created_at"="now()";"Name"="Navasan";"Value"=$rates}
# Update-Supabase -table "data" -data @{"id"=1;"created_at"="now()";"Name"="Navasan";"Value"=$rates}
# $id=Get-Supabase -table "data" -query "select=id"
# Send-Telegram -ChatId 95589475 -Message $content
}
while (1) {
if (Test-Path -Path "./Data/lastrun-quebecirbot.json")
{
$LastRun = Get-Content -Path "./Data/lastrun-quebecirbot.json" | ConvertFrom-csv
}
else
{
$LastRun = (Get-Date).AddDays(-10)
}
if ((NEW-TIMESPAN -Start $LastRun.DateTime -End (Get-Date)).Days -gt 1)
{
send-currency -currency "cad" -chatid -1001942280822 -Telegramtoken $Telegramtoken
if ($debug){Write-Host "get new qute"}
$msg=Get-AskChatGPT -OpenAIKey $OpenAIToken -prompt "give me a poem in persian with name of poet and the name of the poem in persian language"
Send-TelegramTextMessage -BotToken $Telegramtoken -ChatID -1001942280822 -Message $msg -ParseMode HTML #-1001942280822
foreach ($chatid in $chatids) {
Send-Telegram -Message $msg -ChatId $chatid
}
Get-Date | ConvertTo-csv | Out-File -FilePath "./Data/lastrun-quebecirbot.json"
}
Start-Sleep 1
}