Last active
October 29, 2016 01:58
-
-
Save lotabout/4d9b0c5ef0cff077c8d2cee1ab4fe91f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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