File tree 3 files changed +45
-0
lines changed
3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ .ruby-gemset
2
+ .ruby-version
3
+
4
+ imgs /*
5
+ * .gif
Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments