Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2020
1,676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## timer in seconds between retries
  2. $sleepTimer = 30
  3. ## Replace [ZIPCODE] with your zipcode
  4. $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'
  5.  
  6. ## replace with your email and password - this is just for gmail
  7. ## if you use 2 factor authentication for google use the link below on how to create an app password
  8. ## https://support.teamgate.com/hc/en-us/articles/115002064229-How-to-create-a-password-to-connect-email-while-using-2-step-verification-in-Gmail-
  9.  
  10. $email = "[email protected]"
  11. $pass = "yourpassword"
  12.  
  13. $headers = @{
  14.   "authority"="api.target.com"
  15.   "scheme"="https"
  16.   ## Change [ZIPCODE] here as well
  17.   "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"
  18.   "accept"="application/json"
  19.   "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"
  20.   "dnt"="1"
  21.   "origin"="https://www.target.com"
  22.   "sec-fetch-site"="same-site"
  23.   "sec-fetch-mode"="cors"
  24.   "sec-fetch-dest"="empty"
  25.   "referer"="https://www.target.com/p/playstation-5-console/-/A-81114595"
  26.   "accept-encoding"="gzip, deflate, br"
  27.   "accept-language"="en-US,en;q=0.9"
  28.   "Cache-Control"="no-cache"
  29. }
  30.  
  31. function Send-Email {
  32. Param ([string]$body)
  33.  
  34.  
  35.     $smtpServer = "smtp.gmail.com"
  36.  
  37.     $msg = new-object Net.Mail.MailMessage
  38.     $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  39.     $smtp.EnableSsl = $true
  40.     $msg.From = "$email"  
  41.     $msg.To.Add("$email")
  42.     $msg.BodyEncoding = [system.Text.Encoding]::UTF8
  43.     $msg.SubjectEncoding = [system.Text.Encoding]::UTF8
  44.     $msg.IsBodyHTML = $false  
  45.     $msg.Subject = "TARGET IS IN STOCK"
  46.     $msg.Body = $body  
  47.     $SMTP.Credentials = New-Object System.Net.NetworkCredential("$email", "$pass");
  48.     $smtp.Send($msg)
  49. }
  50.  
  51. function Is-In-Stock {
  52. Param ([Object[]]$a)
  53.  
  54.     $itemInStock = 0;
  55.     $locations = "";
  56.     $foundLocations = "";
  57.     foreach ($i in $a.locations)
  58.     {
  59.         $storeInfo = $i.store_name+" "+$i.order_pickup.availability_status+" "+ $i.in_store_only.availability_status+" "+$i.location_available_to_promise_quantity+"`n"
  60.         $locations = $locations+$storeInfo
  61.        
  62.         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") {
  63.             $foundLocations = $foundLocations+$storeInfo;
  64.             $itemInStock += 1;
  65.         }
  66.     }
  67.     if ($itemInStock -gt 0) {
  68.         Send-Email $foundLocations
  69.     }
  70.     Write-Host $locations
  71.     return $itemInStock;
  72. }
  73.  
  74. do
  75. {
  76.     try {
  77.         $timeStamp = [int][double]::Parse((Get-Date -UFormat %s))
  78.         $stampedApi = $api+"&tstmp="+$timestamp
  79.         $response = Invoke-RestMethod -Uri ($stampedApi) -Method "GET" -Headers $headers
  80.        
  81.         Write-Host $timeStamp
  82.         $productList = $response.products
  83.         $isInStock = Is-In-Stock ($productList)
  84.     } catch {
  85.         $isInStock = 0
  86.         Write-Host 'Request Failed'
  87.     }
  88.  
  89.   Start-Sleep -s $sleepTimer
  90. }
  91. until($isInStock -gt 0)
  92.  
  93.  
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement