pyama-camp 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a0d3fbcddcd78788188fe461f1f4db11a40976c8089b1df8269ccc01ace798e
4
+ data.tar.gz: 1ff2fe6258c0a331a2bc2205b31224193deb69a7badfa72fbb59cb9529e01021
5
+ SHA512:
6
+ metadata.gz: 99ca45ea5704d9ec4c90c974e9afc7e8bcb885acab794f0e83bc1c7f870c1b36d1688c615be0904f45485ffb80f700de59a083485996a9dcb6607652e0b9e62e
7
+ data.tar.gz: 1723ee84469d3dd78bfb5b16f9ac4123e012529e32ac87359b7b683bc6fc5726abf93d61cff37b3dbf6a9e24cdd0dc5fd39a8e62a70f460794637eda532be65b
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pyama-camp (0.0.1)
5
+ nokogiri
6
+ thor
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ method_source (1.0.0)
14
+ mini_portile2 (2.4.0)
15
+ nokogiri (1.10.10)
16
+ mini_portile2 (~> 2.4.0)
17
+ pry (0.13.1)
18
+ coderay (~> 1.1)
19
+ method_source (~> 1.0)
20
+ pry-byebug (3.9.0)
21
+ byebug (~> 11.0)
22
+ pry (~> 0.13.0)
23
+ thor (1.0.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler
30
+ pry-byebug
31
+ pyama-camp!
32
+
33
+ BUNDLED WITH
34
+ 2.1.4
@@ -0,0 +1,17 @@
1
+ # pyama camp
2
+
3
+ 各地のキャンプ上の空き状況を取得するライブラリです。下記のように利用してください。
4
+
5
+ ```ruby
6
+ require 'pyama-camp'
7
+
8
+ Camp.can_reserve_sites(Date.parse("2021/1/16"))
9
+ # ["Montbell B Site", "Montbell C Site", "Hadomisaki"]
10
+ ```
11
+
12
+ 予約できるサイト名が返却されるので、必要に応じてSlack通知するなどして、即予約してください。
13
+
14
+ ## 対応しているキャンプサイト
15
+
16
+ - 五ケ山クロス モンベルB/Cサイト
17
+ - 波戸岬キャンプ場
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'camp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pyama-camp"
8
+ spec.version = Camp::VERSION
9
+ spec.authors = ["pyama86"]
10
+ spec.email = ["www.kazu.com@gmail.com"]
11
+
12
+ spec.summary = %q{I want to Go camping.}
13
+ spec.description = %q{I want to Go camping.}
14
+ spec.homepage = "https://github.com/pyama86/camp/"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_dependency "nokogiri"
23
+ spec.add_development_dependency "pry-byebug"
24
+ spec.add_development_dependency "bundler"
25
+ end
@@ -0,0 +1,3 @@
1
+ require 'camp'
2
+
3
+ pp Camp.can_reserve_sites(Date.parse("2021/1/18"))
@@ -0,0 +1,18 @@
1
+ require 'date'
2
+ require 'camp/site'
3
+ require 'camp/montbell'
4
+ require 'camp/hadomisaki'
5
+ require 'nokogiri'
6
+ require 'open-uri'
7
+
8
+ module Camp
9
+ def self.can_reserve_sites(day)
10
+ raise "input parameter must be Date class" if day.class != Date
11
+
12
+ %w(Montbell Hadomisaki).map do |s|
13
+ Object.const_get("Camp::#{s}").sites.map do |site|
14
+ site.name if site.can_reserve?(day)
15
+ end.compact
16
+ end.compact.flatten
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Camp
2
+ module Hadomisaki
3
+ class << self
4
+ def name
5
+ "Hadomisaki"
6
+ end
7
+
8
+ def possible_days(doc)
9
+ doc.xpath('//a').map {|element| element["href"]}.compact.map do |link|
10
+ if link =~ /autocamp.*startdate/
11
+ DateTime.parse(link.gsub(/.*startdate=([0-9]{4}-[0-9]{2}-[0-9]{2}).*/, '\1'))
12
+ end
13
+ end.compact
14
+ end
15
+
16
+ def url
17
+ 'https://www.hadomisaki-camp.jp/reservation/calendar/'
18
+ end
19
+
20
+ def sites
21
+ ["", %q(?next=1&period=1#container)].map do |param|
22
+ charset = 'utf-8'
23
+ html = URI.open(url + param) { |f| f.read }
24
+ doc = Nokogiri::HTML.parse(html, nil, charset)
25
+ ::Camp::Site.new(name, possible_days(doc))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ require 'camp/montbell/base'
2
+ require 'camp/montbell/b_site'
3
+ require 'camp/montbell/c_site'
4
+
5
+ module Camp
6
+ module Montbell
7
+ SITES = %w(Bsite Csite)
8
+ def self.sites
9
+ charset = 'utf-8'
10
+ SITES.map do |s|
11
+ site = Object.const_get("Camp::Montbell::#{s}").new
12
+ html = URI.open(site.url) { |f| f.read }
13
+ doc = Nokogiri::HTML.parse(html, nil, charset)
14
+ ::Camp::Site.new(site.site_name, site.possible_days(doc))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Camp
2
+ module Montbell
3
+ class Bsite < Base
4
+ def site_name
5
+ "Montbell B Site"
6
+ end
7
+
8
+ def url
9
+ 'https://booking.montbell.jp/lodging/site.php?site_id=3'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Camp
2
+ module Montbell
3
+ class Base
4
+ def site_name
5
+ raise 'site_name required'
6
+ end
7
+
8
+ def url
9
+ raise 'url required'
10
+ end
11
+
12
+ def possible_days(doc)
13
+ doc.xpath('//a').map {|element| element["href"]}.compact.map do |link|
14
+ if link =~ /start_date/
15
+ DateTime.parse(link.gsub(/.*start_date=/, ''))
16
+ end
17
+ end.compact
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Camp
2
+ module Montbell
3
+ class Csite < Base
4
+ def site_name
5
+ "Montbell C Site"
6
+ end
7
+
8
+ def url
9
+ 'https://booking.montbell.jp/lodging/site.php?site_id=4'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Camp
2
+ class Site
3
+ attr_reader :name, :possible_days
4
+ def initialize(name, possible_days)
5
+ @name = name
6
+ @possible_days = possible_days
7
+ end
8
+
9
+ def can_reserve?(day)
10
+ possible_days.find {|d| d == day}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Camp
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pyama-camp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - pyama86
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: pry-byebug
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: bundler
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
+ description: I want to Go camping.
70
+ email:
71
+ - www.kazu.com@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.md
79
+ - Rakefile
80
+ - camp.gemspec
81
+ - example.rb
82
+ - lib/camp.rb
83
+ - lib/camp/hadomisaki.rb
84
+ - lib/camp/montbell.rb
85
+ - lib/camp/montbell/b_site.rb
86
+ - lib/camp/montbell/base.rb
87
+ - lib/camp/montbell/c_site.rb
88
+ - lib/camp/site.rb
89
+ - lib/camp/version.rb
90
+ homepage: https://github.com/pyama86/camp/
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.1.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: I want to Go camping.
112
+ test_files: []