ramesh 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/.travis.yml +5 -0
- data/README.md +3 -0
- data/Rakefile +6 -0
- data/bin/ramesh +21 -23
- data/lib/ramesh.rb +3 -3
- data/lib/ramesh/client.rb +28 -28
- data/lib/ramesh/image.rb +50 -0
- data/lib/ramesh/logger.rb +11 -0
- data/lib/ramesh/version.rb +1 -1
- data/ramesh.gemspec +5 -1
- data/spec/fixtures/index.js +2 -0
- data/spec/fixtures/lena.png +0 -0
- data/spec/ramesh/client_spec.rb +66 -24
- data/spec/ramesh/image_spec.rb +74 -0
- data/spec/ramesh/logger_spec.rb +20 -0
- data/spec/ramesh_spec.rb +5 -0
- data/spec/spec_helper.rb +8 -0
- metadata +87 -24
- data/lib/ramesh/image_util.rb +0 -34
- data/lib/ramesh/util.rb +0 -27
- data/spec/ramesh/image_util_spec.rb +0 -30
- data/spec/ramesh/util_spec.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 864cf2072c0d6e2fadf44f5f5bf45bca20b02ee4
|
4
|
+
data.tar.gz: cebbb43a3842d404dd8a9f86b6e79f7a1aac9414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9172e4821c9e2f94fc3738b8905a408dfe11d145a64a01841099bcea2a4cdc82aa9d59aa1c200df347cc0d9428d5a0075232bb9c42f8608994c1fb5e3aa0084
|
7
|
+
data.tar.gz: 8bed25633c866e135e3e26438fa14075c4afcda2fd0530cca94f5e869e53931503a76afcca3c58cefe1cddaa0d75c0d90fcf66fbe0f2db220c999442b9420c4e
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format
|
2
|
+
--format doc
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Ramesh
|
2
|
+
[![Build Status](https://travis-ci.org/dtan4/ramesh.svg?branch=master)](https://travis-ci.org/dtan4/ramesh)
|
3
|
+
[![Coverage Status](https://img.shields.io/coveralls/dtan4/ramesh.svg)](https://coveralls.io/r/dtan4/ramesh?branch=master)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/dtan4/ramesh.png)](https://codeclimate.com/github/dtan4/ramesh)
|
2
5
|
|
3
6
|
Command Line Tool for [東京アメッシュ (Tokyo-Amesh)](http://tokyo-ame.jwa.or.jp/)
|
4
7
|
|
data/Rakefile
CHANGED
data/bin/ramesh
CHANGED
@@ -1,36 +1,34 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require "optparse"
|
6
4
|
require "ramesh"
|
7
5
|
|
8
6
|
USAGE = <<-EOS
|
9
7
|
Usage:
|
10
|
-
ramesh
|
11
|
-
ramesh [0-120
|
12
|
-
ramesh [0-120
|
13
|
-
ramesh -h
|
8
|
+
ramesh [-d save_dir] download the latest image
|
9
|
+
ramesh [-d save_dir] 0-120 download the image specified minutes before
|
10
|
+
ramesh [-d save_dir] 0-120 0-120 download images within a specified range
|
11
|
+
ramesh -h, --help show this usage
|
14
12
|
EOS
|
15
13
|
|
16
|
-
|
14
|
+
save_dir = Dir.pwd
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
parser = OptionParser.new(USAGE) do |opt|
|
17
|
+
opt.on("-d", "--dir=VAL", "Save directory (default: current directory)") { |val| save_dir = val }
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
if ARGV.include?('-h')
|
23
|
-
puts USAGE
|
24
|
-
exit
|
25
|
-
end
|
20
|
+
argv = parser.parse(ARGV)
|
26
21
|
|
27
|
-
|
22
|
+
client = Ramesh::Client.new(Ramesh::Logger.new(STDOUT))
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
case argv.length
|
25
|
+
when 0
|
26
|
+
client.download_image(save_dir)
|
27
|
+
when 1
|
28
|
+
client.download_image(save_dir, argv[0].to_i)
|
29
|
+
when 2
|
30
|
+
client.download_sequential_images(save_dir, argv[0].to_i, argv[1].to_i)
|
31
|
+
else
|
32
|
+
$stderr.puts USAGE
|
33
|
+
exit 1
|
36
34
|
end
|
data/lib/ramesh.rb
CHANGED
data/lib/ramesh/client.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
module Ramesh
|
2
2
|
class Client
|
3
|
-
|
4
|
-
include ImageUtil
|
3
|
+
MESHES_INDEX_URL = "http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js"
|
5
4
|
|
6
|
-
def initialize
|
7
|
-
@
|
5
|
+
def initialize(logger)
|
6
|
+
@logger = logger
|
8
7
|
end
|
9
8
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
unless range.length == 2
|
14
|
-
$stderr.puts "error: invalid range"
|
15
|
-
exit 1
|
9
|
+
def download_image(save_dir, minute = 0)
|
10
|
+
unless valid_minutes?(minute)
|
11
|
+
raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120"
|
16
12
|
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
exit 1
|
22
|
-
end
|
23
|
-
end
|
14
|
+
image_name = name_from_minute(minute)
|
15
|
+
image = Image.new(image_name)
|
16
|
+
image.save(save_dir, image_name)
|
24
17
|
|
25
|
-
|
18
|
+
@logger.info("Downloaded: #{image_name}.jpg")
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
def download_sequential_images(save_dir, from, to)
|
22
|
+
unless valid_minutes?(from) && valid_minutes?(to)
|
23
|
+
raise ArgumentError, "minutes must be a number; 0, 5, 10, ... 120"
|
30
24
|
end
|
31
|
-
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
$stderr.puts "error: minutes must be a number; 0, 5, 10, ... 120"
|
36
|
-
exit 1
|
26
|
+
(from..to).step(5) do |minute|
|
27
|
+
download_image(save_dir, minute)
|
37
28
|
end
|
29
|
+
end
|
38
30
|
|
39
|
-
|
40
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def meshes_index
|
34
|
+
@meshes_index ||= open(MESHES_INDEX_URL).read.gsub(/[^0-9,]/, "").split(",")
|
35
|
+
end
|
36
|
+
|
37
|
+
def name_from_minute(minute)
|
38
|
+
meshes_index[minute / 5]
|
39
|
+
end
|
41
40
|
|
42
|
-
|
41
|
+
def valid_minutes?(minutes)
|
42
|
+
(minutes >= 0) && (minutes <= 120) && (minutes % 5 == 0)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/ramesh/image.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "RMagick"
|
2
|
+
require "open-uri"
|
3
|
+
|
4
|
+
module Ramesh
|
5
|
+
class Image
|
6
|
+
MESH_URL_BASE = "http://tokyo-ame.jwa.or.jp/mesh/000/"
|
7
|
+
BACKGROUND_IMAGE_URL = "http://tokyo-ame.jwa.or.jp/map/map000.jpg"
|
8
|
+
MASK_IMAGE_URL = "http://tokyo-ame.jwa.or.jp/map/msk000.png"
|
9
|
+
|
10
|
+
def self.background_image
|
11
|
+
download_image(BACKGROUND_IMAGE_URL)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.mask_image
|
15
|
+
download_image(MASK_IMAGE_URL)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(image_name,
|
19
|
+
background_image = self.class.background_image,
|
20
|
+
mask_image = self.class.mask_image)
|
21
|
+
image_list = [
|
22
|
+
background_image,
|
23
|
+
self.class.download_image(moment_image_url(image_name)),
|
24
|
+
mask_image
|
25
|
+
]
|
26
|
+
@image = composite_images(image_list)
|
27
|
+
end
|
28
|
+
|
29
|
+
def save(save_dir, image_name)
|
30
|
+
save_path = File.join(save_dir, "#{image_name}.jpg")
|
31
|
+
@image.write(save_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.download_image(url)
|
37
|
+
Magick::Image.from_blob(open(url).read).shift
|
38
|
+
end
|
39
|
+
|
40
|
+
def moment_image_url(image_name)
|
41
|
+
"#{MESH_URL_BASE}#{image_name}.gif"
|
42
|
+
end
|
43
|
+
|
44
|
+
def composite_images(image_list)
|
45
|
+
image = image_list.shift
|
46
|
+
image_list.each { |layer| image = image.composite(layer, 0, 0, Magick::OverCompositeOp) }
|
47
|
+
image
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/ramesh/version.rb
CHANGED
data/ramesh.gemspec
CHANGED
@@ -19,9 +19,13 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "coveralls"
|
23
|
+
spec.add_development_dependency "fakefs"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
22
25
|
spec.add_development_dependency "rake"
|
23
26
|
spec.add_development_dependency "rspec"
|
24
|
-
spec.add_development_dependency "guard
|
27
|
+
spec.add_development_dependency "terminal-notifier-guard"
|
28
|
+
spec.add_development_dependency "webmock"
|
25
29
|
|
26
30
|
spec.add_dependency "rmagick"
|
27
31
|
end
|
@@ -0,0 +1,2 @@
|
|
1
|
+
Amesh.setIndexList(["201405091845","201405091840","201405091835","201405091830","201405091825","201405091820","201405091815","201405091810","201405091805","201405091800","201405091755","201405091750","201405091745","201405091740","201405091735","201405091730","201405091725","201405091720","201405091715","201405091710","201405091705","201405091700","201405091655","201405091650","201405091645"]);
|
2
|
+
|
Binary file
|
data/spec/ramesh/client_spec.rb
CHANGED
@@ -1,47 +1,89 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "fileutils"
|
2
3
|
|
3
4
|
module Ramesh
|
4
5
|
describe Client do
|
5
|
-
let(:
|
6
|
+
let(:logger) do
|
7
|
+
double("logger", info: true)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:client) do
|
11
|
+
Ramesh::Client.new(logger)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:tmpdir) do
|
15
|
+
File.expand_path(File.join("..", "..", "tmp"), __FILE__)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:meshes_index_url) do
|
19
|
+
"http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js"
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
stub_request(:get, meshes_index_url)
|
24
|
+
.to_return(status: 200, body: open(fixture_path("index.js")))
|
25
|
+
Dir.mkdir(tmpdir)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#download_image" do
|
29
|
+
before do
|
30
|
+
image = double(write: true)
|
31
|
+
Image.stub(download_image: image)
|
32
|
+
Image.any_instance.stub(composite_images: image)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when minute is not specified" do
|
36
|
+
it "should download the current image" do
|
37
|
+
expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091845").once
|
38
|
+
client.download_image(tmpdir)
|
39
|
+
end
|
6
40
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
client.download_sequential_image('0-20')
|
11
|
-
Dir.glob("*.gif").length.should == 5
|
41
|
+
it "should log the result" do
|
42
|
+
expect(logger).to receive(:info).with("Downloaded: 201405091845.jpg")
|
43
|
+
client.download_image(tmpdir)
|
12
44
|
end
|
13
45
|
end
|
14
46
|
|
15
|
-
context "
|
16
|
-
it "should download
|
17
|
-
|
18
|
-
|
47
|
+
context "when valid minute is specified" do
|
48
|
+
it "should download the image of the specified minutes ago" do
|
49
|
+
expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815").once
|
50
|
+
client.download_image(tmpdir, 30)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should log the result" do
|
54
|
+
expect(logger).to receive(:info).with("Downloaded: 201405091815.jpg")
|
55
|
+
client.download_image(tmpdir, 30)
|
19
56
|
end
|
20
57
|
end
|
21
58
|
|
22
|
-
context "
|
23
|
-
it "should
|
24
|
-
|
25
|
-
|
59
|
+
context "when invalid minute is specified" do
|
60
|
+
it "should raise ArgumentError" do
|
61
|
+
expect do
|
62
|
+
client.download_image(tmpdir, 7)
|
63
|
+
end.to raise_error ArgumentError
|
26
64
|
end
|
27
65
|
end
|
66
|
+
end
|
28
67
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
68
|
+
describe "#download_sequential_images" do
|
69
|
+
context "when valid section is specified" do
|
70
|
+
it "should download the images" do
|
71
|
+
expect_any_instance_of(Client).to receive(:download_image).exactly(7).times
|
72
|
+
client.download_sequential_images(tmpdir, 0, 30)
|
33
73
|
end
|
34
74
|
end
|
35
75
|
|
36
|
-
context "
|
37
|
-
it "should
|
38
|
-
|
76
|
+
context "when invalid section is specified" do
|
77
|
+
it "should raise ArgumentError" do
|
78
|
+
expect do
|
79
|
+
client.download_sequential_images(tmpdir, 1, 2)
|
80
|
+
end.to raise_error ArgumentError
|
39
81
|
end
|
40
82
|
end
|
41
83
|
end
|
42
84
|
|
43
|
-
after
|
44
|
-
|
85
|
+
after do
|
86
|
+
FileUtils.rm_rf(tmpdir)
|
45
87
|
end
|
46
88
|
end
|
47
89
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module Ramesh
|
5
|
+
describe Image do
|
6
|
+
let(:image_name) do
|
7
|
+
"201405091845"
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:tmpdir) do
|
11
|
+
File.expand_path(File.join("..", "..", "tmp"), __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:mesh_url) do
|
15
|
+
"http://tokyo-ame.jwa.or.jp/mesh/000/#{image_name}.gif"
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:background_url) do
|
19
|
+
"http://tokyo-ame.jwa.or.jp/map/map000.jpg"
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:mask_url) do
|
23
|
+
"http://tokyo-ame.jwa.or.jp/map/msk000.png"
|
24
|
+
end
|
25
|
+
|
26
|
+
before do
|
27
|
+
stub_request(:get, mesh_url)
|
28
|
+
.to_return(status: 200, body: open(fixture_path("lena.png")).read)
|
29
|
+
stub_request(:get, background_url)
|
30
|
+
.to_return(status: 200, body: open(fixture_path("lena.png")).read)
|
31
|
+
stub_request(:get, mask_url)
|
32
|
+
.to_return(status: 200, body: open(fixture_path("lena.png")).read)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#background_image" do
|
36
|
+
it "should download the background image" do
|
37
|
+
described_class.background_image
|
38
|
+
expect(a_request(:get, background_url)).to have_been_made.once
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#mask_image" do
|
43
|
+
it "should download the mask image" do
|
44
|
+
described_class.mask_image
|
45
|
+
expect(a_request(:get, mask_url)).to have_been_made.once
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#initialize" do
|
50
|
+
it "should composite the moment image" do
|
51
|
+
described_class.new(image_name)
|
52
|
+
expect(a_request(:get, mesh_url)).to have_been_made.once
|
53
|
+
expect(a_request(:get, background_url)).to have_been_made.once
|
54
|
+
expect(a_request(:get, mask_url)).to have_been_made.once
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#save" do
|
59
|
+
before do
|
60
|
+
Dir.mkdir(tmpdir)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should save itself to the file" do
|
64
|
+
image = described_class.new(image_name)
|
65
|
+
image.save(tmpdir, image_name)
|
66
|
+
expect(File.exist?(File.join(tmpdir, "#{image_name}.jpg"))).to be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
after do
|
70
|
+
FileUtils.rm_rf(tmpdir)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Ramesh
|
4
|
+
describe Logger do
|
5
|
+
let(:output) do
|
6
|
+
double("output", puts: true)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:logger) do
|
10
|
+
described_class.new(output)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#info" do
|
14
|
+
it "should flush message" do
|
15
|
+
logger.info("message")
|
16
|
+
expect(output).to have_received(:puts).with("message")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/ramesh_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
1
4
|
require 'ramesh'
|
5
|
+
require 'webmock/rspec'
|
2
6
|
|
3
7
|
RSpec.configure do |config|
|
4
8
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
@@ -11,3 +15,7 @@ RSpec.configure do |config|
|
|
11
15
|
# --seed 1234
|
12
16
|
config.order = 'random'
|
13
17
|
end
|
18
|
+
|
19
|
+
def fixture_path(name)
|
20
|
+
File.expand_path(File.join("..", "fixtures", name), __FILE__)
|
21
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramesh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dtan4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fakefs
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: rake
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
|
-
- -
|
73
|
+
- - ">="
|
32
74
|
- !ruby/object:Gem::Version
|
33
75
|
version: '0'
|
34
76
|
type: :development
|
35
77
|
prerelease: false
|
36
78
|
version_requirements: !ruby/object:Gem::Requirement
|
37
79
|
requirements:
|
38
|
-
- -
|
80
|
+
- - ">="
|
39
81
|
- !ruby/object:Gem::Version
|
40
82
|
version: '0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: rspec
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
|
-
- -
|
87
|
+
- - ">="
|
46
88
|
- !ruby/object:Gem::Version
|
47
89
|
version: '0'
|
48
90
|
type: :development
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
52
|
-
- -
|
94
|
+
- - ">="
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: '0'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard
|
98
|
+
name: terminal-notifier-guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
58
114
|
requirements:
|
59
|
-
- -
|
115
|
+
- - ">="
|
60
116
|
- !ruby/object:Gem::Version
|
61
117
|
version: '0'
|
62
118
|
type: :development
|
63
119
|
prerelease: false
|
64
120
|
version_requirements: !ruby/object:Gem::Requirement
|
65
121
|
requirements:
|
66
|
-
- -
|
122
|
+
- - ">="
|
67
123
|
- !ruby/object:Gem::Version
|
68
124
|
version: '0'
|
69
125
|
- !ruby/object:Gem::Dependency
|
70
126
|
name: rmagick
|
71
127
|
requirement: !ruby/object:Gem::Requirement
|
72
128
|
requirements:
|
73
|
-
- -
|
129
|
+
- - ">="
|
74
130
|
- !ruby/object:Gem::Version
|
75
131
|
version: '0'
|
76
132
|
type: :runtime
|
77
133
|
prerelease: false
|
78
134
|
version_requirements: !ruby/object:Gem::Requirement
|
79
135
|
requirements:
|
80
|
-
- -
|
136
|
+
- - ">="
|
81
137
|
- !ruby/object:Gem::Version
|
82
138
|
version: '0'
|
83
139
|
description: Command Line Tool for Tokyo-Amesh
|
@@ -88,8 +144,9 @@ executables:
|
|
88
144
|
extensions: []
|
89
145
|
extra_rdoc_files: []
|
90
146
|
files:
|
91
|
-
- .gitignore
|
92
|
-
- .rspec
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".travis.yml"
|
93
150
|
- Gemfile
|
94
151
|
- Guardfile
|
95
152
|
- LICENSE.txt
|
@@ -98,13 +155,16 @@ files:
|
|
98
155
|
- bin/ramesh
|
99
156
|
- lib/ramesh.rb
|
100
157
|
- lib/ramesh/client.rb
|
101
|
-
- lib/ramesh/
|
102
|
-
- lib/ramesh/
|
158
|
+
- lib/ramesh/image.rb
|
159
|
+
- lib/ramesh/logger.rb
|
103
160
|
- lib/ramesh/version.rb
|
104
161
|
- ramesh.gemspec
|
162
|
+
- spec/fixtures/index.js
|
163
|
+
- spec/fixtures/lena.png
|
105
164
|
- spec/ramesh/client_spec.rb
|
106
|
-
- spec/ramesh/
|
107
|
-
- spec/ramesh/
|
165
|
+
- spec/ramesh/image_spec.rb
|
166
|
+
- spec/ramesh/logger_spec.rb
|
167
|
+
- spec/ramesh_spec.rb
|
108
168
|
- spec/spec_helper.rb
|
109
169
|
homepage: https://github.com/dtan4/ramesh
|
110
170
|
licenses:
|
@@ -116,23 +176,26 @@ require_paths:
|
|
116
176
|
- lib
|
117
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
178
|
requirements:
|
119
|
-
- -
|
179
|
+
- - ">="
|
120
180
|
- !ruby/object:Gem::Version
|
121
181
|
version: '0'
|
122
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
183
|
requirements:
|
124
|
-
- -
|
184
|
+
- - ">="
|
125
185
|
- !ruby/object:Gem::Version
|
126
186
|
version: '0'
|
127
187
|
requirements: []
|
128
188
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.2.2
|
130
190
|
signing_key:
|
131
191
|
specification_version: 4
|
132
192
|
summary: Tokyo-Amesh Downloader
|
133
193
|
test_files:
|
194
|
+
- spec/fixtures/index.js
|
195
|
+
- spec/fixtures/lena.png
|
134
196
|
- spec/ramesh/client_spec.rb
|
135
|
-
- spec/ramesh/
|
136
|
-
- spec/ramesh/
|
197
|
+
- spec/ramesh/image_spec.rb
|
198
|
+
- spec/ramesh/logger_spec.rb
|
199
|
+
- spec/ramesh_spec.rb
|
137
200
|
- spec/spec_helper.rb
|
138
201
|
has_rdoc:
|
data/lib/ramesh/image_util.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'RMagick'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
|
-
module Ramesh::ImageUtil
|
5
|
-
MESH_URL_BASE ='http://tokyo-ame.jwa.or.jp/mesh/000/'
|
6
|
-
BACKGROUND_IMAGE_URL = 'http://tokyo-ame.jwa.or.jp/map/map000.jpg'
|
7
|
-
MAP_MASK_URL = 'http://tokyo-ame.jwa.or.jp/map/msk000.png'
|
8
|
-
|
9
|
-
include Magick
|
10
|
-
|
11
|
-
def create_moment_image(gif_name)
|
12
|
-
mesh_url = MESH_URL_BASE + gif_name
|
13
|
-
|
14
|
-
@background_image ||= Image.from_blob(open(BACKGROUND_IMAGE_URL).read).shift
|
15
|
-
@map_image ||= Image.from_blob(open(MAP_MASK_URL).read).shift
|
16
|
-
|
17
|
-
begin
|
18
|
-
image_list = [
|
19
|
-
@background_image,
|
20
|
-
Image.from_blob(open(mesh_url).read).shift,
|
21
|
-
@map_image
|
22
|
-
]
|
23
|
-
moment_image = composite_images(image_list)
|
24
|
-
moment_image.write(gif_name)
|
25
|
-
rescue OpenURI::HTTPError
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def composite_images(image_list)
|
30
|
-
image = image_list.shift
|
31
|
-
image_list.each { |layer| image = image.composite(layer, 0, 0, OverCompositeOp) }
|
32
|
-
image
|
33
|
-
end
|
34
|
-
end
|
data/lib/ramesh/util.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'time'
|
3
|
-
|
4
|
-
module Ramesh::Util
|
5
|
-
AMESH_INDEXES_URL = 'http://tokyo-ame.jwa.or.jp/scripts/mesh_index.js'
|
6
|
-
|
7
|
-
def extract_filename(url)
|
8
|
-
if url =~ /.+\/([a-zA-Z0-9._-]+)$/
|
9
|
-
$1
|
10
|
-
else
|
11
|
-
''
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_mesh_indexes
|
16
|
-
begin
|
17
|
-
indexes_js = open(AMESH_INDEXES_URL).read
|
18
|
-
indexes = indexes_js.gsub(/[^0-9,]/, '').split(',')
|
19
|
-
rescue
|
20
|
-
$stderr.puts 'Failed to download: #{AMESH_INDEXES_URL}'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def validate_minutes(minutes)
|
25
|
-
(minutes >= 0) && (minutes <= 120) && (minutes % 5 == 0)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Ramesh
|
4
|
-
describe ImageUtil do
|
5
|
-
include Ramesh::ImageUtil
|
6
|
-
|
7
|
-
describe "#create_moment_image" do
|
8
|
-
before(:all) do
|
9
|
-
current_time = Time.now
|
10
|
-
year = current_time.year
|
11
|
-
month = current_time.month
|
12
|
-
day = current_time.day
|
13
|
-
hour = current_time.hour
|
14
|
-
|
15
|
-
@gif = sprintf('%04d%02d%02d%02d00.gif', year, month, day, hour)
|
16
|
-
create_moment_image(@gif)
|
17
|
-
end
|
18
|
-
|
19
|
-
context "downloaded image" do
|
20
|
-
it "should exist" do
|
21
|
-
File.exist?(@gif).should be_true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
after(:all) do
|
26
|
-
File.delete(@gif) if File.exists?(@gif)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/ramesh/util_spec.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'time'
|
3
|
-
|
4
|
-
module Ramesh
|
5
|
-
describe Util do
|
6
|
-
include Ramesh::Util
|
7
|
-
|
8
|
-
describe '#extract_filename' do
|
9
|
-
context 'http://tokyo-ame.jwa.or.jp/map/map000.jpg' do
|
10
|
-
it 'should return "map000.jpg"' do
|
11
|
-
extract_filename('http://tokyo-ame.jwa.or.jp/map/map000.jpg').should == 'map000.jpg'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'http://tokyo-ame.jwa.or.jp/map/' do
|
16
|
-
it 'should return ""' do
|
17
|
-
extract_filename('http://tokyo-ame.jwa.or.jp/map/').should == ''
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#get_mesh_indexes' do
|
23
|
-
before(:all) do
|
24
|
-
@indexes = get_mesh_indexes
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'downloaded indexes' do
|
28
|
-
it 'should be Array' do
|
29
|
-
@indexes.class.should == Array
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should be sorted decrementally' do
|
33
|
-
@indexes.should == @indexes.sort.reverse
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should have 25 items' do
|
37
|
-
@indexes.length.should == 25
|
38
|
-
end
|
39
|
-
|
40
|
-
25.times do |i|
|
41
|
-
it "indexes[#{i}] should be 12 digit number" do
|
42
|
-
@indexes[i].should =~ /^\d{12}$/
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#validate_minutes" do
|
49
|
-
context "0" do
|
50
|
-
it 'should be true' do
|
51
|
-
validate_minutes(0).should be_true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "5" do
|
56
|
-
it 'should be true' do
|
57
|
-
validate_minutes(5).should be_true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "7" do
|
62
|
-
it 'should be false' do
|
63
|
-
validate_minutes(7).should be_false
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "120" do
|
68
|
-
it 'should be true' do
|
69
|
-
validate_minutes(120).should be_true
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "130" do
|
74
|
-
it 'should be false' do
|
75
|
-
validate_minutes(130).should be_false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "-5" do
|
80
|
-
it 'should be false' do
|
81
|
-
validate_minutes(130).should be_false
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|