Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## timer in seconds between retries
- $sleepTimer = 30
- ## Replace [ZIPCODE] with your zipcode
- $api = 'https://api.target.com/fulfillment_aggregator/v1/fiats/81114595?key=ff457966e64d5e877fdbad070f276d18ecec4a01&nearby=[ZIPCODE]&limit=20&requested_quantity=1&radius=50&fulfillment_test_mode=grocery_opu_team_member_test'
- ## replace with your email and password - this is just for gmail
- ## if you use 2 factor authentication for google use the link below on how to create an app password
- ## https://support.teamgate.com/hc/en-us/articles/115002064229-How-to-create-a-password-to-connect-email-while-using-2-step-verification-in-Gmail-
- $pass = "yourpassword"
- $headers = @{
- "authority"="api.target.com"
- "scheme"="https"
- ## Change [ZIPCODE] here as well
- "path"="/fulfillment_aggregator/v1/fiats/81114595?key=ff457966e64d5e877fdbad070f276d18ecec4a01&nearby=[ZIPCODE]&limit=20&requested_quantity=1&radius=50&fulfillment_test_mode=grocery_opu_team_member_test"
- "accept"="application/json"
- "user-agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36 Edg/87.0.664.47"
- "dnt"="1"
- "origin"="https://www.target.com"
- "sec-fetch-site"="same-site"
- "sec-fetch-mode"="cors"
- "sec-fetch-dest"="empty"
- "referer"="https://www.target.com/p/playstation-5-console/-/A-81114595"
- "accept-encoding"="gzip, deflate, br"
- "accept-language"="en-US,en;q=0.9"
- "Cache-Control"="no-cache"
- }
- function Send-Email {
- Param ([string]$body)
- $smtpServer = "smtp.gmail.com"
- $msg = new-object Net.Mail.MailMessage
- $smtp = new-object Net.Mail.SmtpClient($smtpServer)
- $smtp.EnableSsl = $true
- $msg.From = "$email"
- $msg.To.Add("$email")
- $msg.BodyEncoding = [system.Text.Encoding]::UTF8
- $msg.SubjectEncoding = [system.Text.Encoding]::UTF8
- $msg.IsBodyHTML = $false
- $msg.Subject = "TARGET IS IN STOCK"
- $msg.Body = $body
- $SMTP.Credentials = New-Object System.Net.NetworkCredential("$email", "$pass");
- $smtp.Send($msg)
- }
- function Is-In-Stock {
- Param ([Object[]]$a)
- $itemInStock = 0;
- $locations = "";
- $foundLocations = "";
- foreach ($i in $a.locations)
- {
- $storeInfo = $i.store_name+" "+$i.order_pickup.availability_status+" "+ $i.in_store_only.availability_status+" "+$i.location_available_to_promise_quantity+"`n"
- $locations = $locations+$storeInfo
- if ($i.location_available_to_promise_quantity -gt 0 -Or $i.order_pickup.availability_status -eq "IN_STOCK" -Or $i.in_store_only.availability_status -eq "IN_STOCK") {
- $foundLocations = $foundLocations+$storeInfo;
- $itemInStock += 1;
- }
- }
- if ($itemInStock -gt 0) {
- Send-Email $foundLocations
- }
- Write-Host $locations
- return $itemInStock;
- }
- do
- {
- try {
- $timeStamp = [int][double]::Parse((Get-Date -UFormat %s))
- $stampedApi = $api+"&tstmp="+$timestamp
- $response = Invoke-RestMethod -Uri ($stampedApi) -Method "GET" -Headers $headers
- Write-Host $timeStamp
- $productList = $response.products
- $isInStock = Is-In-Stock ($productList)
- } catch {
- $isInStock = 0
- Write-Host 'Request Failed'
- }
- Start-Sleep -s $sleepTimer
- }
- until($isInStock -gt 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement