Advertisement
Guest User

PSA In stock notification

a guest
Apr 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.04 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'nokogiri'
  4.  
  5. require 'open-uri'
  6.  
  7. require 'aws-sdk-sns'
  8.  
  9. require 'time'
  10.  
  11.  
  12. url = "https://palmettostatearmory.com/psa-ar-15-approval-15-stripped-lower-receiver.html"
  13.  
  14. data = Nokogiri::HTML(open(url))
  15.  
  16. key = 'XXX'
  17.  
  18. secret = 'XXX'
  19.  
  20. aws_account = 'MY_ACCOUNT_HERE'
  21.  
  22. sns_topic = 'InStock'
  23.  
  24.  
  25. sns = Aws::SNS::Resource.new(region: 'us-east-1', access_key_id: key, secret_access_key: secret)
  26.  
  27. topic = sns.topic("arn:aws:sns:us-east-1:#{aws_account}:#{sns_topic}")
  28.  
  29.  
  30. timestamp = Time.now
  31.  
  32.  
  33. begin
  34.  
  35. stock_info = data.at_css(".product-availability").text.strip
  36.  
  37.  
  38. if stock_info.include?("In stock")
  39.  
  40. topic.publish({message: "ATF lower is in stock!!!"})
  41.  
  42. puts "#{timestamp} IS"
  43.  
  44. elsif stock_info.include?("OUT OF STOCK")
  45.  
  46. puts "#{timestamp} NIS"
  47.  
  48. else
  49.  
  50. puts "#{timestamp} Stock info not set proper: #{stock_info}"
  51.  
  52. topic.publish({message: "Some other thing: #{stock_info}"})
  53.  
  54. end
  55.  
  56. rescue Exception => e
  57.  
  58. puts "#{timestamp} Error: #{e}"
  59.  
  60. topic.publish({message: "Script failed: #{e}"})
  61.  
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement