ramesh 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f1c2c778553c82075773d6562017c63d29cc437
4
+ data.tar.gz: 049c15801d749465b5eaf45761f2782bb897f6cd
5
+ SHA512:
6
+ metadata.gz: 8ad73709a962c6381896e6abe87c2b15523437e2207b1ec0edc8ae7ac83a2a2927211713e0ed42adf1f855302bec76741b4ef5770512b7df456e422417701df2
7
+ data.tar.gz: 44063836324cd4706057dfd1edb0d50f6632833d889099e5b28dddc5ee3111eb39a7ac56d3660a11a63da5bfd01ea286c47e920a481c76eed2d361cd133b2277
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ramesh.gemspec
4
+ gemspec
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 dtan4
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # Ramesh
2
+
3
+ Command Line Tool for [東京アメッシュ (Tokyo-Amesh)](http://tokyo-ame.jwa.or.jp/)
4
+
5
+ ## Installation
6
+
7
+ At first, you need to install [ImageMagick](http://www.imagemagick.org/script/index.php) (if you haven't installed yet).
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'ramesh'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ramesh
20
+
21
+ ## Usage
22
+
23
+ ramesh download the latest image
24
+ ramesh [0-120] download the image specified minutes before
25
+ ramesh [0-120]-[0-120] download images within a specified range
26
+ ramesh -h show this usage
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
6
+ require "ramesh"
7
+
8
+ USAGE = <<-EOS
9
+ Usage:
10
+ ramesh download the latest image
11
+ ramesh [0-120] download the image specified minutes before
12
+ ramesh [0-120]-[0-120] download images within a specified range
13
+ ramesh -h show this usage
14
+ EOS
15
+
16
+ client = Ramesh::Client.new
17
+
18
+ if ARGV.length == 0
19
+ client.download_moment_image
20
+
21
+ else
22
+ if ARGV.include?('-h')
23
+ puts USAGE
24
+ exit
25
+ end
26
+
27
+ arg = ARGV.shift
28
+
29
+ if arg =~ /^(?:0|[1-9]\d*)$/
30
+ client.download_moment_image(arg.to_i)
31
+ elsif arg =~ /^(?:0|[1-9]\d*)-(?:0|[1-9]\d*)$/
32
+ client.download_sequential_image(arg)
33
+ else
34
+ $stderr.puts USAGE
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ require "ramesh/version"
2
+ require "ramesh/util"
3
+ require "ramesh/image_util"
4
+ require "ramesh/client"
@@ -0,0 +1,45 @@
1
+ module Ramesh
2
+ class Client
3
+ include Util
4
+ include ImageUtil
5
+
6
+ def initialize
7
+ @indexes = get_mesh_indexes
8
+ end
9
+
10
+ def download_sequential_image(minute_range)
11
+ range = minute_range.split('-').map { |num| num.to_i }.sort
12
+
13
+ unless range.length == 2
14
+ $stderr.puts "error: invalid range"
15
+ exit 1
16
+ end
17
+
18
+ range.each do |min|
19
+ unless validate_minutes(min)
20
+ $stderr.puts "error: minutes must be a number; 0, 5, 10, ... 120"
21
+ exit 1
22
+ end
23
+ end
24
+
25
+ minute = range[0]
26
+
27
+ while minute <= range[1]
28
+ download_moment_image(minute)
29
+ minute += 5
30
+ end
31
+ end
32
+
33
+ def download_moment_image(minutes = 0)
34
+ unless validate_minutes(minutes)
35
+ $stderr.puts "error: minutes must be a number; 0, 5, 10, ... 120"
36
+ exit 1
37
+ end
38
+
39
+ download_index = @indexes[minutes / 5]
40
+ create_moment_image("#{download_index}.gif")
41
+
42
+ puts "Successfully downloaded: #{download_index}.gif"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
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
+ begin
15
+ image_list = [
16
+ Image.from_blob(open(BACKGROUND_IMAGE_URL).read).shift,
17
+ Image.from_blob(open(mesh_url).read).shift,
18
+ Image.from_blob(open(MAP_MASK_URL).read).shift
19
+ ]
20
+ moment_image = composite_images(image_list)
21
+ moment_image.write(gif_name)
22
+ rescue OpenURI::HTTPError
23
+ end
24
+ end
25
+
26
+ def composite_images(image_list)
27
+ image = image_list.shift
28
+ image_list.each { |layer| image = image.composite(layer, 0, 0, OverCompositeOp) }
29
+ image
30
+ end
31
+ end
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,3 @@
1
+ module Ramesh
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ramesh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ramesh"
8
+ spec.version = Ramesh::VERSION
9
+ spec.authors = ["dtan4"]
10
+ spec.email = ["dtanshi45@gmail.com"]
11
+ spec.description = %q{Command Line Tool for Tokyo-Amesh}
12
+ spec.summary = %q{Tokyo-Amesh Downloader}
13
+ spec.homepage = "https://github.com/dtan4/ramesh"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+
26
+ spec.add_dependency "rmagick"
27
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module Ramesh
4
+ describe Client do
5
+ let(:client) { client = Ramesh::Client.new }
6
+
7
+ describe "#download_sequential_image" do
8
+ context "0-20" do
9
+ it "should download 5 images" do
10
+ client.download_sequential_image('0-20')
11
+ Dir.glob("*.gif").length.should == 5
12
+ end
13
+ end
14
+
15
+ context "20-0" do
16
+ it "should download 5 images" do
17
+ client.download_sequential_image('20-0')
18
+ Dir.glob("*.gif").length.should == 5
19
+ end
20
+ end
21
+
22
+ context "30-80" do
23
+ it "should download 11 images" do
24
+ client.download_sequential_image('30-80')
25
+ Dir.glob("*.gif").length.should == 11
26
+ end
27
+ end
28
+
29
+ context "0-120" do
30
+ it "should download 25 images" do
31
+ client.download_sequential_image('0-120')
32
+ Dir.glob("*.gif").length.should == 25
33
+ end
34
+ end
35
+
36
+ context "0-130" do
37
+ it "should not download any image" do
38
+ lambda { client.download_sequential_image('0-130') }.should raise_error SystemExit
39
+ end
40
+ end
41
+ end
42
+
43
+ after(:each) do
44
+ Dir.glob("*.gif").each { |gif| File.delete(gif) }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,86 @@
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
@@ -0,0 +1,13 @@
1
+ require 'ramesh'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+
8
+ # Run specs in random order to surface order dependencies. If you find an
9
+ # order dependency and want to debug it, you can fix the order by providing
10
+ # the seed, which is printed after each run.
11
+ # --seed 1234
12
+ config.order = 'random'
13
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ramesh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - dtan4
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: rspec
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rmagick
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Command Line Tool for Tokyo-Amesh
84
+ email:
85
+ - dtanshi45@gmail.com
86
+ executables:
87
+ - ramesh
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - Guardfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/ramesh
99
+ - lib/ramesh.rb
100
+ - lib/ramesh/client.rb
101
+ - lib/ramesh/image_util.rb
102
+ - lib/ramesh/util.rb
103
+ - lib/ramesh/version.rb
104
+ - ramesh.gemspec
105
+ - spec/ramesh/client_spec.rb
106
+ - spec/ramesh/image_util_spec.rb
107
+ - spec/ramesh/util_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: https://github.com/dtan4/ramesh
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Tokyo-Amesh Downloader
133
+ test_files:
134
+ - spec/ramesh/client_spec.rb
135
+ - spec/ramesh/image_util_spec.rb
136
+ - spec/ramesh/util_spec.rb
137
+ - spec/spec_helper.rb