Module: Himawari

Defined in:
lib/himawari.rb,
lib/himawari/base.rb,
lib/himawari/process.rb,
lib/himawari/download.rb,
lib/himawari/os_utils.rb,
lib/himawari/net_utils.rb

Overview

require ‘pry’

Defined Under Namespace

Modules: NetUtils, OsUtils, Process Classes: Base, Download

Constant Summary collapse

MONITOR_ASPECT =

This Aspect Ratio is used to try and download the most appropriate Tiles from Himawari, while omitting those that won’t be visible. (used by the :focus param)

16.0 / 9
UPDATE_RATE =

int; update the pic once every ‘UPDATE_RATE` minutes

2
HIMAWARI_URL =

Yep, that’s the big one. Where we actually download everything from

'https://himawari8-dl.nict.go.jp/himawari8/img/D531106'
LOCAL_MIDNIGHT =

Local (JST) midnight happens @14:10 UTC, so we have to use pics in interval of [2.days.ago@14:40 .. 1.day.ago@14:40]

'1410'

Class Method Summary collapse

Class Method Details

.autorun(params = {}) ⇒ Object

all-in-one method. downloads images, sets backgrounds, crontabs, whatever

Parameters:

  • params (Hash) (defaults to: {})

    any combination of the acceptable command line args you can throw at it. Plz see README for the list/description

Returns:

  • nothing useful



16
17
18
19
# File 'lib/himawari.rb', line 16

def self.autorun(params = {})
  h = Download.new(params)
  h.cron_action ? h.crontab : h.update_backgrnd ^ h.start
end

.get_pic(params = {}) ⇒ true, false

downloads 1 picture from himawari website, closest (but in the past of) the ‘:datetime` provided in the params

Parameters:

  • any (Hash)

    combination of the acceptable command line args + THE REQUIRED ‘:datetime` additional stamp

Returns:

  • (true, false)

    on success/failure



24
25
26
27
# File 'lib/himawari.rb', line 24

def self.get_pic(params = {})
  t = validate(params[:datetime])
  Download.new(params).pic(t, OsUtils.tenmin(t.min, t.min))
end

.get_pics(params = {}) ⇒ true, false

downloads many pictures from himawari website, in the range of [:from, :to] provided in the params

Parameters:

  • any (Hash)

    combination of the acceptable command line args + THE REQUIRED ‘:from` && `:to` timestamps

Returns:

  • (true, false)

    on success/failure



32
33
34
# File 'lib/himawari.rb', line 32

def self.get_pics(params = {})
  Download.new(params).pics(validate(params[:from]), validate(params[:to]))
end

.validate(stamp) ⇒ DateTime

validates the user-provided timestamps coming from ‘get_pic` or `get_pics` methods

Parameters:

  • stamp (DateTime, String)

Returns:

  • (DateTime)

    of the stamp, or the most recent round 10-minute mark to Time.now - 10.minutes



39
40
41
42
43
44
45
# File 'lib/himawari.rb', line 39

def self.validate(stamp)
  return stamp if stamp.is_a? Time
  return Time.parse("#{stamp}+00:00") if stamp.is_a? String

  t = Time.now.utc - 600 # 600secs == 10.minutes ago
  Time.new(t.year, t.month, t.day, t.hour, t.min / 10 * 10, 0, '+00:00')
end