edm_festival_finder 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/edm_festival_finder +5 -0
- data/bin/setup +8 -0
- data/edm_festival_finder-0.1.6.gem +0 -0
- data/edm_festival_finder.gemspec +37 -0
- data/lib/edm_festival_finder.rb +8 -0
- data/lib/edm_festival_finder/cli.rb +130 -0
- data/lib/edm_festival_finder/festival.rb +34 -0
- data/lib/edm_festival_finder/scraper.rb +54 -0
- data/lib/edm_festival_finder/version.rb +3 -0
- data/spec.md +12 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9ec94e08846f85bb45c4c1eec68de6e1cfa42a1
|
4
|
+
data.tar.gz: 6708db387b358c50188e1c04ee04c7fc4279b6d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f70a932a2dcb21e78c8605220b3eeda65eeeff2d4f92500d40082cec9927a30d6dcc274fb2cce55a25872df158b3e9c9cf9bfd887530b4ccb60967656f20fd48
|
7
|
+
data.tar.gz: 5fe27129a32d7b75ddd5fe55b4b6c406ae9f70be03254d1c5ac328f15e0d01fc0d79e2852635ff835148acc1702ac191c48845c42b553841f4796e2ec1e54e48
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jluk87@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
edm_festival_finder (0.1.0)
|
5
|
+
nokogiri
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
method_source (0.9.0)
|
13
|
+
mini_portile2 (2.3.0)
|
14
|
+
nokogiri (1.8.2)
|
15
|
+
mini_portile2 (~> 2.3.0)
|
16
|
+
pry (0.11.3)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.9.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.1)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.1)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bundler (~> 1.16)
|
39
|
+
edm_festival_finder!
|
40
|
+
pry
|
41
|
+
rake (~> 10.0)
|
42
|
+
rspec (~> 3.0)
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jonathan Luk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# EdmFestivalFinder
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/edm_festival_finder`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
Pre-requisites:
|
6
|
+
|
7
|
+
Ruby 2.4.0 or higher
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'edm_festival_finder'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install edm_festival_finder
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Simply enter the command below to run the application:
|
28
|
+
|
29
|
+
$ edm_festival_finder
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
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).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/edm_festival_finder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
44
|
+
|
45
|
+
## Code of Conduct
|
46
|
+
|
47
|
+
Everyone interacting in the EdmFestivalFinder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gitluky/edm_festival_finder/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "edm_festival_finder"
|
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(__FILE__)
|
data/bin/setup
ADDED
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "edm_festival_finder/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "edm_festival_finder"
|
8
|
+
spec.version = EdmFestivalFinder::VERSION
|
9
|
+
spec.authors = ["Jonathan Luk"]
|
10
|
+
spec.email = ["jluk87@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Scrapes http://www.electronic-festivals.com for electronic festivals in the country selected by user input within a year of the current date }
|
13
|
+
spec.homepage = "https://github.com/gitluky/edm_festival_finder"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
# "public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "pry"
|
36
|
+
spec.add_dependency "nokogiri"
|
37
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
class EdmFestivalFinder::CLI
|
2
|
+
|
3
|
+
attr_accessor :startdate, :enddate, :country_code, :festival_count, :festival_num, :current_festivals
|
4
|
+
|
5
|
+
def initialize #new instance sets the start date to the current date and end date a year from the current date
|
6
|
+
self.startdate = Date.today.to_s
|
7
|
+
self.enddate = Date.today.next_year.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def call #puts out the landing screen and prompts user to press enter before listing the countrys
|
11
|
+
puts " _____) ______ __ __)"
|
12
|
+
puts " / (, / ) (, /| /|"
|
13
|
+
puts " )__ / / / | / |"
|
14
|
+
puts " / _/___ /_ ) / |/ |_"
|
15
|
+
puts " (_____) (_/___ / (_/ FESTIVAL FINDER"
|
16
|
+
puts ""
|
17
|
+
puts "Electronic Festivals between #{EdmFestivalFinder::CLI.new.startdate} to #{EdmFestivalFinder::CLI.new.enddate}"
|
18
|
+
puts ""
|
19
|
+
puts " [Press enter to choose country]"
|
20
|
+
puts ""
|
21
|
+
input = gets
|
22
|
+
until input == "\n"
|
23
|
+
input = gets
|
24
|
+
end
|
25
|
+
self.choose_country
|
26
|
+
end
|
27
|
+
|
28
|
+
def choose_country(no_results="") #lists the countries
|
29
|
+
country_hash = EdmFestivalFinder::Scraper.scrape_countries #scrapes the list of countries from the site
|
30
|
+
country_hash.each do #displays the countries next to their country code
|
31
|
+
|country,code| puts " #{code} - #{country}"
|
32
|
+
end
|
33
|
+
if block_given?
|
34
|
+
yield(no_results) #puts "No results found..." when get_festivals is called and there are no concerts found for the country"
|
35
|
+
end
|
36
|
+
puts "Enter the country code for the country of choice listed above or type 'back' or 'exit'" #prompts user to enter country code
|
37
|
+
self.country_code = gets.strip #sets @country_code to input
|
38
|
+
self.back_or_exit(self.country_code, 1)
|
39
|
+
while country_hash.none? {|country,code| self.country_code == code} #re-prompts if the country code until the country code is one from the list provided
|
40
|
+
puts "Country code was not valid, please re-enter."
|
41
|
+
self.country_code = gets.strip #resets @country_code to correct input
|
42
|
+
self.back_or_exit(self.country_code, 1)
|
43
|
+
end
|
44
|
+
puts "Searching, please wait, this may take a minute." #tells user to wait as the festivals are being retrieved by #get_festivals
|
45
|
+
self.get_festivals
|
46
|
+
end
|
47
|
+
|
48
|
+
def no_results_found #no results found message to yield in #choose_country
|
49
|
+
"No results found for the country."
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_festivals
|
53
|
+
if EdmFestivalFinder::Festival.all.find {|festival| festival.country_code == self.country_code}
|
54
|
+
self.display_festivals
|
55
|
+
else
|
56
|
+
#scrapes the search results from searching the website with filters: @country_code, @startdate and @enddate
|
57
|
+
search_results = EdmFestivalFinder::Scraper.scrape_festivals(self.country_code, self.startdate, self.enddate)
|
58
|
+
if search_results == []
|
59
|
+
self.choose_country(self.no_results_found) {|x| puts x} #yields #no_results_found if scrape returns an empty array
|
60
|
+
else
|
61
|
+
EdmFestivalFinder::Festival.create_from_search(search_results) #creates festivals from the array of festival hashes returned from the scrape
|
62
|
+
EdmFestivalFinder::Festival.all.each do |festival| #for each festival object, the instance variables are set from a hash created scraped from festival.individual_page
|
63
|
+
festival.add_additional_details(EdmFestivalFinder::Scraper.scrape_individual_festivals(festival.individual_page))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
self.display_festivals
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def display_festivals #displays a numbered list of festivals and some details
|
71
|
+
self.festival_count = 0
|
72
|
+
#binding.pry
|
73
|
+
self.current_festivals = EdmFestivalFinder::Festival.all.select {|festival| festival if festival.country_code == self.country_code}
|
74
|
+
self.current_festivals.each do |festival|
|
75
|
+
self.festival_count +=1
|
76
|
+
puts "#{self.festival_count}. #{festival.name}"
|
77
|
+
puts " #{festival.country}, #{festival.startdate} - #{festival.enddate} (dd/mm/yy)"
|
78
|
+
end
|
79
|
+
self.choose_festival
|
80
|
+
end
|
81
|
+
|
82
|
+
def choose_festival
|
83
|
+
#validates user input for festival selection by number, the number is then passed onto festival_details to be used as the EdmFestivalFinder::Festival.all index number
|
84
|
+
#at this point user will be able to input back or exit
|
85
|
+
puts "Enter the number for the festival to see more details or type 'back' or 'exit'"
|
86
|
+
self.festival_num = gets.strip
|
87
|
+
self.back_or_exit(self.festival_num, 2)
|
88
|
+
while !self.festival_num.to_i.between?(1,self.festival_count)
|
89
|
+
puts "Please re-enter the number, or type 'back' or 'exit'"
|
90
|
+
self.festival_num = gets.strip
|
91
|
+
self.back_or_exit(self.festival_num, 2)
|
92
|
+
end
|
93
|
+
self.festival_num = self.festival_num.to_i - 1
|
94
|
+
self.festival_details
|
95
|
+
end
|
96
|
+
|
97
|
+
def festival_details #puts out the festival instance variables of EdmFestivalFinder::Festival.all[@festival_num]
|
98
|
+
puts ""
|
99
|
+
puts "Name: #{self.current_festivals[self.festival_num].name}"
|
100
|
+
puts "Country: #{self.current_festivals[self.festival_num].country}"
|
101
|
+
puts "Date: #{self.current_festivals[self.festival_num].startdate} - #{EdmFestivalFinder::Festival.all[self.festival_num].enddate}"
|
102
|
+
puts "Confirmed acts: #{self.current_festivals[self.festival_num].confirmed_acts}"
|
103
|
+
puts "Attendance: #{self.current_festivals[self.festival_num].attendance}"
|
104
|
+
puts "Environment: #{self.current_festivals[self.festival_num].environment}"
|
105
|
+
puts "Type of event: #{self.current_festivals[self.festival_num].type_of_event}"
|
106
|
+
puts "Link: #{self.current_festivals[self.festival_num].link}"
|
107
|
+
puts "Facebook: #{self.current_festivals[self.festival_num].facebook}"
|
108
|
+
puts ""
|
109
|
+
puts "Type 'back' to go to the festival list or 'exit'"
|
110
|
+
input = gets.strip
|
111
|
+
self.back_or_exit(input, 3)
|
112
|
+
end
|
113
|
+
|
114
|
+
def back_or_exit(input, go_to) #verifies input for 'back' or 'exit' and routes user to the correct screen. When input is back, the go_to values are: 1 = main screen, 2 = choose_country, 3 = display_festivals.
|
115
|
+
if input == 'back'
|
116
|
+
if go_to == 1
|
117
|
+
self.call
|
118
|
+
elsif go_to == 2
|
119
|
+
#EdmFestivalFinder::Festival.reset_all
|
120
|
+
choose_country
|
121
|
+
elsif go_to == 3
|
122
|
+
display_festivals
|
123
|
+
end
|
124
|
+
elsif input == 'exit'
|
125
|
+
puts "Thank you for using EDM Festival Finder, Goodbye."
|
126
|
+
exit
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class EdmFestivalFinder::Festival
|
2
|
+
@@all = []
|
3
|
+
|
4
|
+
attr_accessor :name, :country_code, :country, :startdate, :enddate, :environment, :attendance, :confirmed_acts, :type_of_event, :individual_page, :link, :facebook
|
5
|
+
|
6
|
+
def initialize(festival_hash) #initializes with a hash, sets instance variables and adds self to @@all
|
7
|
+
festival_hash.each do |attribute, value|
|
8
|
+
self.send("#{attribute}=", value)
|
9
|
+
end
|
10
|
+
self.class.all << self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create_from_search(array_of_festivals) #class constructor to take in an array of hashes and initialize a new festival object with each hash
|
14
|
+
array_of_festivals.each do |festival_hash|
|
15
|
+
EdmFestivalFinder::Festival.new(festival_hash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_additional_details(festival_detail_hash) #takes a hash as an argument and sets the instance variables
|
20
|
+
festival_detail_hash.each do |attribute, value|
|
21
|
+
self.send("#{attribute}=", value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.all
|
26
|
+
@@all
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.reset_all
|
30
|
+
self.all.clear
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class EdmFestivalFinder::Scraper
|
2
|
+
|
3
|
+
def self.scrape_countries #scrapes and creates a hash { country: code, ...} from the dropdown list of countries on the website
|
4
|
+
url = "http://www.electronic-festivals.com"
|
5
|
+
@@doc ||= Nokogiri::HTML(open(url))
|
6
|
+
country_hash = {}
|
7
|
+
@@doc.css(".location_auto_country option").each do |country|
|
8
|
+
country_hash[country.text.to_sym]=country.attribute("value").value
|
9
|
+
end
|
10
|
+
country_hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.scrape_festivals(country_code, start_date, end_date) #uses arguments as filters in the URL, creates an array and inserts hashes for each festival scraped from the search results on the page
|
14
|
+
start_date = start_date.gsub("-","")
|
15
|
+
end_date = end_date.gsub("-","")
|
16
|
+
array_of_festivals = []
|
17
|
+
url = "http://www.electronic-festivals.com/home/result?title=&field_genre_tags_tid=All&field_type_of_event_value=All&country=#{country_code}&date_filter%5Bmin%5D%5Bdate%5D=#{start_date[6..7]}%2F#{start_date[4..5]}%2F#{start_date[0..3]}&date_filter%5Bmax%5D%5Bdate%5D=#{end_date[6..7]}%2F#{end_date[4..5]}%2F#{end_date[0..3]}&field_visitors_value=All&field_age_value=All&field_festicket_shop_value=All"
|
18
|
+
doc = Nokogiri::HTML(open(url))
|
19
|
+
festival_blocks = doc.css(".views-row")
|
20
|
+
|
21
|
+
festival_blocks.each do |festival|
|
22
|
+
array_of_festivals << {
|
23
|
+
name: festival.css("h3 a").text,
|
24
|
+
country_code: country_code,
|
25
|
+
country: festival.css(".country-name").text,
|
26
|
+
startdate: festival.css(".date-display-start").text,
|
27
|
+
enddate: festival.css(".date-display-end").text,
|
28
|
+
individual_page: "http://www.electronic-festivals.com/#{festival.css('h3 a').attribute('href').value}",
|
29
|
+
confirmed_acts: "#{festival.css(".col-xs-auto.col-sm-auto.nopadding.right.small").first.text.match(/\d+/)}",
|
30
|
+
attendance: "#{festival.css(".col-xs-auto.col-sm-auto.nopadding.right.small.star").text.match(/\d+\s\d+/)}"
|
31
|
+
}
|
32
|
+
end
|
33
|
+
array_of_festivals
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def self.scrape_individual_festivals(individual_page) #takes a festival's individual page URL, scrapes the page and creates a hash
|
38
|
+
doc = Nokogiri::HTML(open("#{individual_page}"))
|
39
|
+
if !doc.css(".col-xs-12.nopadding.eventlinks.link a").empty?
|
40
|
+
link = doc.css(".col-xs-12.nopadding.eventlinks.link a").attribute("href").value
|
41
|
+
elsif !doc.css(".col-xs-12.nopadding.promoterlinks.link a").empty?
|
42
|
+
link = doc.css(".col-xs-12.nopadding.promoterlinks.link a").attribute("href").value
|
43
|
+
else
|
44
|
+
link = ""
|
45
|
+
end
|
46
|
+
festival_detail_hash = {
|
47
|
+
environment: doc.css("col-xs-auto.col-sm-auto.nopadding.disc").text,
|
48
|
+
type_of_event: doc.css(".col-xs-auto.col-sm-auto.nopadding.nomarginright.disc").text,
|
49
|
+
link: link,
|
50
|
+
facebook: doc.xpath("//div[contains(@class, 'col-xs-12 nopadding link')]/a[contains(@href,'facebook')]").first.text
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [x] Have a CLI for interfacing with the application
|
5
|
+
- [x] Pull data from an external source
|
6
|
+
- [x] Implement both list and detail views
|
7
|
+
|
8
|
+
- the user is taken to the main screen and the countries are displayed when the user presses the enter key
|
9
|
+
- the user can select the country to query
|
10
|
+
- a list of festivals in that country are then returned to the user
|
11
|
+
- the user can select the festival by entering the number next to the festival and is navigated to the detail view of that particular festival
|
12
|
+
- on any screen the user can enter 'back' or 'exit' to navigate to the previous screen or quit the program
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edm_festival_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Luk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-06 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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: nokogiri
|
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:
|
84
|
+
email:
|
85
|
+
- jluk87@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/edm_festival_finder
|
101
|
+
- bin/setup
|
102
|
+
- edm_festival_finder-0.1.6.gem
|
103
|
+
- edm_festival_finder.gemspec
|
104
|
+
- lib/edm_festival_finder.rb
|
105
|
+
- lib/edm_festival_finder/cli.rb
|
106
|
+
- lib/edm_festival_finder/festival.rb
|
107
|
+
- lib/edm_festival_finder/scraper.rb
|
108
|
+
- lib/edm_festival_finder/version.rb
|
109
|
+
- spec.md
|
110
|
+
homepage: https://github.com/gitluky/edm_festival_finder
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.6.11
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Scrapes http://www.electronic-festivals.com for electronic festivals in the
|
134
|
+
country selected by user input within a year of the current date
|
135
|
+
test_files: []
|