Skip to content

Instantly share code, notes, and snippets.

@pasterp
Created October 3, 2019 19:57
Show Gist options
  • Save pasterp/c0e5389bb1274d038c4d34c157369585 to your computer and use it in GitHub Desktop.
Save pasterp/c0e5389bb1274d038c4d34c157369585 to your computer and use it in GitHub Desktop.
require 'httparty'
require 'fileutils'
require 'open-uri'
require 'nokogiri'
base_url = "http://www.bonjourmadame.fr"
page = ""
regex = /<img SRC="(.+)" alt="/i
output_dir = Dir.home+'/.bjmadame/'
FileUtils.mkdir_p output_dir
response = HTTParty.get(base_url+page)
if response.code == 200
page = Nokogiri::HTML(response.body)
img = page.css('img.alignnone').first
url = img['src']
filename = url.split('/').last
puts filename
File.open(output_dir + filename, "wb" ) do |file|
open(url, "rb") do |img|
file.write(img.read)
end
end
system("hsetroot -cover #{output_dir + filename}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment