Skip to content

Commit 7774c17

Browse files
committed
initial
0 parents  commit 7774c17

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.ruby-gemset
2+
.ruby-version
3+
4+
imgs/*
5+
*.gif

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Just a quick script that scrapes the US Drought Monitor weekly images and creates a GIF based on the chosen start date and number of weeks.

drought.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'fileutils'
2+
require 'highline/import'
3+
require 'open-uri'
4+
require 'rmagick'
5+
6+
include Magick
7+
8+
BASE_URI = 'http://droughtmonitor.unl.edu/data/pngs'
9+
10+
def filename(d)
11+
"imgs/#{d.strftime('%Y%m%d')}_west_date.png"
12+
end
13+
14+
def url(d)
15+
"#{BASE_URI}/#{d.strftime('%Y%m%d')}/#{d.strftime('%Y%m%d')}_west_date.png"
16+
end
17+
18+
_date = ask('Enter a start date (MM/DD/YYYY): ').split('/')
19+
date = Date.new(_date[2].to_i, _date[0].to_i, _date[1].to_i)
20+
21+
weeks = ask('Enter number of weeks to scrape images for: ').to_i
22+
23+
FileUtils.rm_rf('imgs/') if File.exists?('imgs/')
24+
Dir.mkdir('imgs')
25+
26+
(0..weeks).each do
27+
begin
28+
File.open(filename(date), 'wb') { |f| f.write(open(url(date)).read) }
29+
rescue OpenURI::HTTPError
30+
File.delete(filename(date))
31+
end
32+
33+
date = date - 7
34+
end
35+
36+
gif = ImageList.new(*Dir['imgs/*.png'].sort)
37+
gif.delay = 80
38+
gif.write('drought.gif')
39+

0 commit comments

Comments
 (0)