Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'nokogiri'
- require 'open-uri'
- require 'aws-sdk-sns'
- require 'time'
- url = "https://palmettostatearmory.com/psa-ar-15-approval-15-stripped-lower-receiver.html"
- data = Nokogiri::HTML(open(url))
- key = 'XXX'
- secret = 'XXX'
- aws_account = 'MY_ACCOUNT_HERE'
- sns_topic = 'InStock'
- sns = Aws::SNS::Resource.new(region: 'us-east-1', access_key_id: key, secret_access_key: secret)
- topic = sns.topic("arn:aws:sns:us-east-1:#{aws_account}:#{sns_topic}")
- timestamp = Time.now
- begin
- stock_info = data.at_css(".product-availability").text.strip
- if stock_info.include?("In stock")
- topic.publish({message: "ATF lower is in stock!!!"})
- puts "#{timestamp} IS"
- elsif stock_info.include?("OUT OF STOCK")
- puts "#{timestamp} NIS"
- else
- puts "#{timestamp} Stock info not set proper: #{stock_info}"
- topic.publish({message: "Some other thing: #{stock_info}"})
- end
- rescue Exception => e
- puts "#{timestamp} Error: #{e}"
- topic.publish({message: "Script failed: #{e}"})
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement