Skip to content

Instantly share code, notes, and snippets.

@lotabout
Last active October 29, 2016 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotabout/4d9b0c5ef0cff077c8d2cee1ab4fe91f to your computer and use it in GitHub Desktop.
Save lotabout/4d9b0c5ef0cff077c8d2cee1ab4fe91f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
picture_folder = File.expand_path("~/Pictures/pod")
page = open('http://cn.bing.com/', 'User-Agent' => "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0").read
img_url = page.to_s.scan(/g_img={url: \"(.*?)\",/).last.first
download_url = case img_url
when /^\/\//
'http' + img_url
when /^http/
img_url
else
'http://www.bing.com' + img_url
end
file_name = File.join(picture_folder, download_url.scan(/([^\/]+)/).last.first)
File.open(file_name, 'wb') do |fp|
fp.write open(download_url).read
puts "Downloading from: #{download_url}"
fp.close
end
Process.spawn('fbsetbg', file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment