-
Notifications
You must be signed in to change notification settings - Fork 1
/
alpaca-in-stock.ps1
41 lines (33 loc) · 1.34 KB
/
alpaca-in-stock.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
# DESCRIPTION:
# Check the Appalachian Gear Company website for a particular item in stock
# Medium Watauga
$Url = 'https://appalachiangearcompany.com/collections/mens/products/mens-all-paca-fleece-hoodie?variant=37641607807174'
$Response = Invoke-WebRequest $Url
foreach ($Line in $Response) {
if ($null -ne ($Line | Where-Object { $_ -match 'Medium / Watauga' })) {
$Availability = $Line
}
}
if ($Availability -notmatch "Sold Out") {
Write-Host "Item is in stock! Sending text message."
Send-TwilioSMS
} else {
Write-Host "Item not in stock"
}
function Send-TwilioSMS {
param (
$TwilioSendingNumber = ""
)
$sid = $env:TWILIO_ACCOUNT_SID
$token = $env:TWILIO_AUTH_TOKEN
$number = $env:TWILIO_NUMBER
# Twilio API endpoint and POST params
$url = "https://api.twilio.com/2010-04-01/Accounts/$sid/Messages.json"
$params = @{ To = "+15558675309"; From = $number; Body = "Hello from PowerShell" }
# Create a credential object for HTTP basic auth
$p = $token | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($sid, $p)
# Make API request, selecting JSON properties from response
Invoke-WebRequest $url -Method Post -Credential $credential -Body $params -UseBasicParsing |
ConvertFrom-Json | Select-Object sid, body
}