Created
July 8, 2019 07:55
-
-
Save matiaskorhonen/793496c0337e962b2f43e5618155ecf7 to your computer and use it in GitHub Desktop.
Generate screenshots of all the Euruko sites
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 "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
gem "down" | |
gem "pry" | |
end | |
private def encode_uri_component(val) | |
URI.escape(val, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) | |
end | |
def urlbox(url, options={}, format="png") | |
# The keys are loaded from the environment on Travis CI | |
urlbox_apikey = ENV["URLBOX_API_KEY"] || "key" | |
urlbox_secret = ENV["URLBOX_SECRET"] || "secret" | |
query = { | |
url: url, # required - the url you want to screenshot | |
force: options[:force], # optional - boolean - whether you want to generate a new screenshot rather than receive a previously cached one - this also overwrites the previously cached image | |
full_page: options[:full_page], # optional - boolean - return a screenshot of the full screen | |
thumb_width: options[:thumb_width], # optional - number - thumbnail the resulting screenshot using this width in pixels | |
width: options[:width], # optional - number - set viewport width to use (in pixels) | |
height: options[:height], # optional - number - set viewport height to use (in pixels) | |
quality: options[:quality], # optional - number (0-100) - set quality of the screenshot | |
} | |
query_string = query. | |
sort_by {|s| s[0].to_s }. | |
select {|s| s[1] }. | |
map {|s| s.map {|v| encode_uri_component(v.to_s) }.join("=") }. | |
join("&") | |
token = OpenSSL::HMAC.hexdigest("sha1", urlbox_secret, query_string) | |
"https://api.urlbox.io/v1/#{urlbox_apikey}/#{token}/#{format}?#{query_string}" | |
end | |
(2005..2019).each do |year| | |
url = urlbox("http://euruko#{year}.org", width: 1920, height: 1080) | |
puts url | |
`open '#{url}'` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment