-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck_PS5_Stock.ps1
More file actions
61 lines (43 loc) · 2.15 KB
/
Check_PS5_Stock.ps1
File metadata and controls
61 lines (43 loc) · 2.15 KB
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
############################################################################
#
# PS5 Target Stock Check App
# By: Matt Peterson
# 4/12/22
# _______________________________________
#
# Checking Target stock is easy because they pull the page down
# if they are out of stockso all we do is check to see if we get an
# error and repeat until it's a success. Then# trigger your IFTTT
# and Home Assistant events.
#
############################################################################
# Sets URL to check - I used the Nintendo Switch URL to test the automation triggers
$PS5URL = "https://www.target.com/p/playstation-5-console/-/A-81114595"
# $SwitchURL = "https://www.target.com/p/nintendo-switch-with-neon-blue-and-neon-red-joy-con/-/A-77464001"
# Set Home Assistant call variables
$APIUrl = "http://YourHAAddress:8123/api/" # Replace to match your Home Assistant URL
$EntityId = "automation.turn_on_light_with_front_door" # Obviously replace with your entity ID
$body = ConvertTo-Json @{"entity_id" = "$EntityID"}
$HAToken = "Long__HA__TOKEN" # See HA API documentation if you don't already have a token
$Headers = @{Authorization = "Bearer "+$HAToken}
$service = "automation/trigger" # If you're calling a different service, adjust this. Replace any "." with "/"
$RestUri=$APIUrl+"services/"+$service # This calls a service - adjust if you need
# Define how many seconds to wait between calls to the Target site
$PingWaitSecs = 60
# Set up your IFTTT info to ping GroupMe, Discord, or just get a notification on your phone
$IFTTT = "IFTTT_DEV_KEY"
$IFUri = "https://maker.ifttt.com/trigger/PS5_Stock_Target/with/key/" + $IFTTT # Make sure you get the right trigger name
# Loop until you don't get an error
While ($true){
Try {
Invoke-WebRequest $PS5URL
Break
} Catch {
"Caught" # you don't really need this - I just like to see things work
}
Start-Sleep $PingWaitSecs
}
# Ping your IFTTT automation
Invoke-WebRequest $IFUri
# Ping your Home Assistant API
Invoke-RestMethod -Method Post -Uri $RestUri -Body ($body) -Header $Headers