Skip to content

Instantly share code, notes, and snippets.

@rennex
Created September 4, 2018 05:00
Show Gist options
  • Save rennex/efa311fb764dc94001281fd8621ab7a1 to your computer and use it in GitHub Desktop.
Save rennex/efa311fb764dc94001281fd8621ab7a1 to your computer and use it in GitHub Desktop.
This script checks for changes in the list of 4k G-sync monitors that Jimm's sells.
#!/usr/bin/env ruby
require "nokogiri"
require "open-uri"
filename = "4k_monitors.txt"
old_names = File.readlines(filename).map(&:strip) rescue []
page = Nokogiri::HTML(open("https://www.jimms.fi/fi/Product/List/000-1HJ/oheislaitteet--naytot--g-sync?ob=6&fq=4k"))
product_names = page.css("#productlistdata .p_col_info .p_name").map {|e| e.text.strip }
added = product_names - old_names
if added.any?
puts "New monitor%s discovered:" % (added.size == 1 ? "" : "s")
puts added
puts
end
removed = old_names - product_names
if removed.any?
puts "Monitor%s disappeared from listing:" % (removed.size == 1 ? "" : "s")
puts removed
end
if added.any? or removed.any?
File.open(filename, "w") do |f|
f.puts product_names
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment