Skip to content

Instantly share code, notes, and snippets.

@raulunzue
Created October 11, 2021 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulunzue/46e1a9eec2a6487430e841ee43369b1e to your computer and use it in GitHub Desktop.
Save raulunzue/46e1a9eec2a6487430e841ee43369b1e to your computer and use it in GitHub Desktop.
###############################
## RAUL UNZUE - ELBLOGDENEGU
## PRECIO CRIPTOMONEDA
##############################
$Moneda = "ADA"
## LOG
$Logfile = "/Users/elblogdenegu/Documents/criptomonedas.log"
Start-Transcript -Path $Logfile -Append
# FECHA Y HORA
$date = Get-Date -Format "dd-MM-yyyy"
$hora = Get-Date -Format "HH:mm:ss"
# PRECIO EN EUROS DE ADA
$ADA=Invoke-RestMethod -Uri "https://api.binance.com/api/v3/ticker/price?symbol=ADAEUR" -Method get | Select-Object -ExpandProperty price
# COMPROBAR VALOR
if ($ADA -ge 1)
{
echo "ADA a las $hora del día $date, vale $ADA €, que es mayor que 1 euro"
# ENVIO CORREO DE INFO
$emailSmtpServer = "smtp.servidor.com"
$emailSmtpServerPort = "587"
$emailSmtpUser = "email@dominio.com"
$emailSmtpPass = "Introducir-Contraseña"
$emailFrom = "email@dominio.com"
$emailTo = "emaildestino@dominio.com"
$emailcc="emaildestino2@dominio.com"
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.cc.add($emailcc)
$emailMessage.Subject = "PRECIO DE ADA"
$emailMessage.IsBodyHtml = $true #true or false depends
$emailMessage.Body = "<h2>¡ADA tiene un valor mayor a 100€!</h2>"
$emailMessage.Body += "El precio actual de ADA es de <FONT SIZE=6><strong>$ADA euros</strong></font>"
$emailMessage.Body += "<p>Volveremos a comprobarlo nuevamente cada hora</p>"
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $False
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )
}
else {
echo "ADA a las $hora del día $date, vale $ADA €, que es menor que 1 euro"
}
# EXPORTAMOS A EXCEL
$Output = New-Object -TypeName PSObject -Property @{
Moneda = $Moneda
Precio = $ADA
Hora = $hora
Fecha = $date
} | Select-Object Moneda,Precio,Hora,Fecha
$Output | Export-Csv -NoTypeInformation -Path "/Users/elblogdenegu/Documents/criptomonedas-ADA.csv" -Append
# POPUP EN SESION WINDOWS
#if ($ADA -le 2) {
#wlrmdr -s 25 -f 2 -t PRECIO ADA -m Atencion! El precio de ADA está muy bajo. ¡Deberías comprar!
#}
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment