movie_fetcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +28 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/movie_fetcher +6 -0
- data/lib/movie_fetcher.rb +6 -0
- data/lib/movie_fetcher/fetcher.rb +64 -0
- data/lib/movie_fetcher/version.rb +3 -0
- data/movie_fetcher.gemspec +28 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94b31b68a4340497f854acc234e8b62a4a63c9e8
|
4
|
+
data.tar.gz: e5937205b57eb2affa5fbe16779a13a438947e65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66b6f34ab06a0be442a8b0f68e3aeeaa1e447ed9aa6c1edddb83096b8b3dfc518e48bd8e1ac0807842c3ea44a2f9a6a714ad9777a70e8516a6bba755d7fd06f3
|
7
|
+
data.tar.gz: 8ef1a62671b2f8e5faec196c6d67c23190fe94188fc7c48db67e988baa9bcc53ee5e9722893bd8ccb12c39853f24d5f75bebd563fc95112eebf63cf696a1870c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# MovieFetcher [![Build Status](https://travis-ci.org/korin/movie_fetcher.svg?branch=master)](https://travis-ci.org/korin/movie_fetcher)
|
2
|
+
|
3
|
+
The next film shows in Warsaw.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install movie_fetcher
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
$ movie_fetcher
|
13
|
+
|
14
|
+
## Development
|
15
|
+
|
16
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
17
|
+
|
18
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/movie_fetcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
23
|
+
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
28
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "movie_fetcher"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/movie_fetcher
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module MovieFetcher
|
5
|
+
class Fetcher
|
6
|
+
def initialize(endpoint = nil)
|
7
|
+
@endpoint = endpoint ||
|
8
|
+
"https://www.google.pl/movies?hl=pl&near=Warszawa&dq=filmy+warszawa&sort=1&q=filmy&sa=X&ved=0CB4QxQMoAGoVChMIs-DMheDaxgIVQXdyCh3tcwCJ"
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch
|
12
|
+
get_google_html
|
13
|
+
parse_html
|
14
|
+
find_closest_movie
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def get_google_html
|
20
|
+
@doc = open(@endpoint)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_html
|
24
|
+
@showtimes = []
|
25
|
+
doc = Nokogiri::HTML(@doc)
|
26
|
+
movies = doc.css(".movie")
|
27
|
+
movies.each do |movie|
|
28
|
+
name = movie.css('[itemprop="name"] a').first.content
|
29
|
+
movie.css('.theater').each do |theater|
|
30
|
+
theater_name = theater.css('.name a').first.content
|
31
|
+
theater.css('.times span').each do |start_time|
|
32
|
+
time = start_time.content
|
33
|
+
if time =~ /(\d\d:\d\d)/ && $1
|
34
|
+
@showtimes << Showtime.new(name, theater_name, $1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def sort_showtimes
|
42
|
+
@showtimes.sort do |p, n|
|
43
|
+
p.time <=> n.time
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_closest_movie
|
48
|
+
now = Time.now.strftime('%H:%m')
|
49
|
+
earliest_show_time = nil
|
50
|
+
sort_showtimes.reject do |showtime|
|
51
|
+
too_early = showtime.time < now
|
52
|
+
earliest_show_time ||= !too_early && showtime.time
|
53
|
+
too_early || ( earliest_show_time && showtime.time > earliest_show_time )
|
54
|
+
end.map &:to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
class Showtime < Struct.new(:name, :theater, :time)
|
58
|
+
def to_s
|
59
|
+
"#{name}, #{theater}, #{time}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'movie_fetcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "movie_fetcher"
|
8
|
+
spec.version = MovieFetcher::VERSION
|
9
|
+
spec.authors = ["Rafał Lisowski"]
|
10
|
+
spec.email = ["lisukorin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{The next film shows in Warsaw.}
|
13
|
+
spec.description = %q{The next film shows in Warsaw.}
|
14
|
+
spec.homepage = "https://github.com/korin/movie_fetcher"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "nokogiri"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "timecop"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: movie_fetcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafał Lisowski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: 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: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: The next film shows in Warsaw.
|
84
|
+
email:
|
85
|
+
- lisukorin@gmail.com
|
86
|
+
executables:
|
87
|
+
- movie_fetcher
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- exe/movie_fetcher
|
100
|
+
- lib/movie_fetcher.rb
|
101
|
+
- lib/movie_fetcher/fetcher.rb
|
102
|
+
- lib/movie_fetcher/version.rb
|
103
|
+
- movie_fetcher.gemspec
|
104
|
+
homepage: https://github.com/korin/movie_fetcher
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.7
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: The next film shows in Warsaw.
|
128
|
+
test_files: []
|