ted_talks 0.1.3
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/NOTES.md +3 -0
- data/README.md +31 -0
- data/Rakefile +5 -0
- data/bin/console +14 -0
- data/bin/ted_talks +5 -0
- data/lib/ted_talks.rb +8 -0
- data/lib/ted_talks/cli.rb +114 -0
- data/lib/ted_talks/talk.rb +40 -0
- data/lib/ted_talks/talk_info.rb +33 -0
- data/lib/ted_talks/version.rb +3 -0
- data/ted_talks-0.1.2.gem +0 -0
- data/ted_talks.gemspec +27 -0
- data/ted_talks/.gitignore +9 -0
- data/ted_talks/.rspec +2 -0
- data/ted_talks/.travis.yml +5 -0
- data/ted_talks/CODE_OF_CONDUCT.md +49 -0
- data/ted_talks/Gemfile +4 -0
- data/ted_talks/LICENSE.txt +21 -0
- data/ted_talks/README.md +41 -0
- data/ted_talks/Rakefile +6 -0
- data/ted_talks/bin/console +14 -0
- data/ted_talks/bin/setup +8 -0
- data/ted_talks/lib/ted_talks.rb +5 -0
- data/ted_talks/lib/ted_talks/cli.rb +114 -0
- data/ted_talks/lib/ted_talks/talk.rb +40 -0
- data/ted_talks/lib/ted_talks/talk_info.rb +33 -0
- data/ted_talks/lib/ted_talks/version.rb +3 -0
- data/ted_talks/spec/spec_helper.rb +2 -0
- data/ted_talks/spec/ted_talks_spec.rb +11 -0
- data/ted_talks/ted_talks.gemspec +34 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b34fcdbdb9f0866fdb8c227e695671792a34b91
|
4
|
+
data.tar.gz: 62fb785d4d46cd8c48b866b7c7309008efbd6f9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e197a15668a6a065769820d9fce701a9b599fea104f1af62231461299b3e442900dc9f3c7a862a9dc425b7f9fc15a89a928997df7240914ce004d338ad83ea3
|
7
|
+
data.tar.gz: 1152f34d57e5583d062812824b85d455e688873402f9cb9df86f8ec87895664b376ac14fe34c040e18b1ab4cd81a7cb5a905fbccfeb41c6d5b8f228e1252bea0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 sameera91
|
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.
|
data/NOTES.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# TedTalks
|
2
|
+
|
3
|
+
Welcome! This gem displays the information of the top 10 TED talks in one of several different categories, or lets you search for a talk of your choosing.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ted_talks'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ted_talks
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/ted_talks/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ted-talks"
|
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/ted_talks
ADDED
data/lib/ted_talks.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#Our CLI Controller
|
2
|
+
class TedTalks::CLI
|
3
|
+
|
4
|
+
def call
|
5
|
+
puts "Today's TED ideas worth spreading. Check out the top 10 talks today!"
|
6
|
+
puts " "
|
7
|
+
list_categories
|
8
|
+
menu
|
9
|
+
goodbye
|
10
|
+
end
|
11
|
+
|
12
|
+
def list_talks(url='http://www.ted.com/talks')
|
13
|
+
@talks = TedTalks::Talk.top_talks(url)
|
14
|
+
|
15
|
+
@talks.each.with_index do |talk, i|
|
16
|
+
puts "#{i+1}. #{talk.title} - #{talk.author} - Posted #{talk.date} - Rated #{talk.rating}"
|
17
|
+
puts " "
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def list_categories
|
23
|
+
puts "Here are 7 different categories. Enter the number or name of the category you'd like to see more videos about."
|
24
|
+
puts " "
|
25
|
+
puts "1. Top Talks"
|
26
|
+
puts "2. Technology"
|
27
|
+
puts "3. Entertainment"
|
28
|
+
puts "4. Design"
|
29
|
+
puts "5. Business"
|
30
|
+
puts "6. Science"
|
31
|
+
puts "7. Global Issues"
|
32
|
+
puts " "
|
33
|
+
puts "Or enter search if you would like to search for videos."
|
34
|
+
|
35
|
+
input = gets.strip.downcase
|
36
|
+
|
37
|
+
categories_hash = {
|
38
|
+
"top talks" => "1",
|
39
|
+
"technology" => "2",
|
40
|
+
"entertainment" => "3",
|
41
|
+
"design" => "4",
|
42
|
+
"business" => "5",
|
43
|
+
"science" => "6",
|
44
|
+
"global+issues" => "7"
|
45
|
+
}
|
46
|
+
|
47
|
+
if input.to_i == 1
|
48
|
+
list_talks
|
49
|
+
elsif input.to_i > 1 && input.to_i <= 7
|
50
|
+
url_value = categories_hash.key(input)
|
51
|
+
url = "http://www.ted.com/talks?topics%5B%5D=#{url_value}&sort=newest"
|
52
|
+
list_talks(url)
|
53
|
+
elsif categories_hash.key?(input)
|
54
|
+
url_value = input
|
55
|
+
url = "http://www.ted.com/talks?topics%5B%5D=#{url_value}&sort=newest"
|
56
|
+
list_talks(url)
|
57
|
+
elsif input == "search"
|
58
|
+
puts "Enter your search term."
|
59
|
+
url_value = gets.strip.downcase
|
60
|
+
url_value.gsub! /\s+/, '+'
|
61
|
+
url = "http://www.ted.com/talks?q=#{url_value}&sort=newest"
|
62
|
+
list_talks(url)
|
63
|
+
elsif input == "exit"
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def menu
|
70
|
+
input = nil
|
71
|
+
|
72
|
+
while input != "exit"
|
73
|
+
puts " "
|
74
|
+
puts "Enter the number of the talk you'd like to learn more about."
|
75
|
+
puts "Enter talks to see the talks again."
|
76
|
+
puts "Enter categories to see the categories again."
|
77
|
+
puts "Enter exit to end the program."
|
78
|
+
|
79
|
+
input = gets.strip.downcase
|
80
|
+
|
81
|
+
if input.to_i > 0
|
82
|
+
the_talk = @talks[input.to_i - 1]
|
83
|
+
@talk_info = TedTalks::Info.talk_info(the_talk.url)
|
84
|
+
display_talk_info(@talk_info)
|
85
|
+
elsif input == "talks"
|
86
|
+
list_talks
|
87
|
+
elsif input == "categories"
|
88
|
+
list_categories
|
89
|
+
elsif input != "exit"
|
90
|
+
puts "Invalid entry."
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def display_talk_info(talk_info)
|
96
|
+
puts " "
|
97
|
+
puts "------------------TED------------------------"
|
98
|
+
puts talk_info.author
|
99
|
+
puts talk_info.title
|
100
|
+
puts " "
|
101
|
+
puts "-----------------Details---------------------"
|
102
|
+
puts talk_info.description
|
103
|
+
puts " "
|
104
|
+
puts "Time #{talk_info.time} "
|
105
|
+
puts talk_info.date
|
106
|
+
puts " "
|
107
|
+
puts "Total views: #{talk_info.views} "
|
108
|
+
puts "----------------------------------------------"
|
109
|
+
end
|
110
|
+
|
111
|
+
def goodbye
|
112
|
+
puts "See you tomorrow for more talks."
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class TedTalks::Talk
|
2
|
+
|
3
|
+
attr_accessor :title, :author, :date, :rating, :url, :description, :time, :date, :views
|
4
|
+
|
5
|
+
def initialize(title=nil, author=nil, date=nil, rating=nil, url=nil)
|
6
|
+
@title = title
|
7
|
+
@author = author
|
8
|
+
@date = date
|
9
|
+
@rating = rating
|
10
|
+
@@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.top_talks(url='http://www.ted.com/talks')
|
14
|
+
|
15
|
+
talk_array = []
|
16
|
+
|
17
|
+
doc = Nokogiri::HTML(open(url))
|
18
|
+
|
19
|
+
title = doc.css(".media__message").css("h4.h9").css("a")
|
20
|
+
author = doc.css(".media__message").css("h4.h12")
|
21
|
+
date = doc.css(".media__message").css(".meta").css(".meta__item").css("span.meta__val")
|
22
|
+
rating = doc.css(".media__message").css(".meta").css(".meta__row").css(".meta__val")
|
23
|
+
url = doc.css("h4.h9").css("a")
|
24
|
+
|
25
|
+
(0..9).each do |i|
|
26
|
+
|
27
|
+
talk = self.new
|
28
|
+
talk.title = title[i].text.strip! if title[i] != nil
|
29
|
+
talk.author = author[i].text if author[i] != nil
|
30
|
+
talk.date = date[i].text.strip! if date[i] != nil
|
31
|
+
talk.rating = rating[i].text.strip! if rating[i] != nil
|
32
|
+
talk.url = "http://www.ted.com" + url[i].attr("href") if url[i] != nil
|
33
|
+
|
34
|
+
talk_array << talk if talk.title != nil
|
35
|
+
end
|
36
|
+
|
37
|
+
talk_array
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class TedTalks::Info
|
2
|
+
|
3
|
+
attr_accessor :title, :author, :description, :time, :date, :views
|
4
|
+
|
5
|
+
def initialize(title=nil, author=nil, description=nil, time=nil, date=nil, views=nil)
|
6
|
+
@title = title
|
7
|
+
@author = author
|
8
|
+
@description = description
|
9
|
+
@time = time
|
10
|
+
@date = date
|
11
|
+
@@views = views
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.talk_info(url='http://www.ted.com/talks')
|
15
|
+
doc = Nokogiri::HTML(open(url))
|
16
|
+
|
17
|
+
author = doc.search("div.player-hero__speaker").search("span.player-hero__speaker__content")
|
18
|
+
title = doc.search("div.player-hero__title").search("span.player-hero__title__content")
|
19
|
+
description = doc.search(".talk-subsection").search(".talk-top__details").search("p.talk-description")
|
20
|
+
time = doc.search("div.player-hero__meta").search("span")
|
21
|
+
date = doc.search("div.player-hero__meta").search("span")
|
22
|
+
views = doc.search("div.talk-sharing__count").search("span.talk-sharing__value")
|
23
|
+
|
24
|
+
talk_info = self.new
|
25
|
+
talk_info.author = author.text
|
26
|
+
talk_info.title = title.text
|
27
|
+
talk_info.description = description.text
|
28
|
+
talk_info.time = time[0].text
|
29
|
+
talk_info.date = date[1].text
|
30
|
+
talk_info.views = views.text.strip!
|
31
|
+
talk_info
|
32
|
+
end
|
33
|
+
end
|
data/ted_talks-0.1.2.gem
ADDED
Binary file
|
data/ted_talks.gemspec
ADDED
@@ -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 'ted_talks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ted_talks"
|
8
|
+
spec.version = TedTalks::VERSION
|
9
|
+
spec.authors = ["sameera91"]
|
10
|
+
spec.email = ["sbachoti91@gmail.com"]
|
11
|
+
spec.summary = "This gem displays information on the latest TED talks."
|
12
|
+
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_development_dependency "nokogiri"
|
27
|
+
end
|
data/ted_talks/.rspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at sameera.bachoti@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/ted_talks/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 sameera91
|
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/ted_talks/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# TedTalks
|
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/ted_talks`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ted_talks'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ted_talks
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ted_talks. 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.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/ted_talks/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ted_talks"
|
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/ted_talks/bin/setup
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#Our CLI Controller
|
2
|
+
class TedTalks::CLI
|
3
|
+
|
4
|
+
def call
|
5
|
+
puts "Today's TED ideas worth spreading. Check out the top 10 talks today!"
|
6
|
+
puts " "
|
7
|
+
list_categories
|
8
|
+
menu
|
9
|
+
goodbye
|
10
|
+
end
|
11
|
+
|
12
|
+
def list_talks(url='http://www.ted.com/talks')
|
13
|
+
@talks = TedTalks::Talk.top_talks(url)
|
14
|
+
|
15
|
+
@talks.each.with_index do |talk, i|
|
16
|
+
puts "#{i+1}. #{talk.title} - #{talk.author} - Posted #{talk.date} - Rated #{talk.rating}"
|
17
|
+
puts " "
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def list_categories
|
23
|
+
puts "Here are 7 different categories. Enter the number or name of the category you'd like to see more videos about."
|
24
|
+
puts " "
|
25
|
+
puts "1. Top Talks"
|
26
|
+
puts "2. Technology"
|
27
|
+
puts "3. Entertainment"
|
28
|
+
puts "4. Design"
|
29
|
+
puts "5. Business"
|
30
|
+
puts "6. Science"
|
31
|
+
puts "7. Global Issues"
|
32
|
+
puts " "
|
33
|
+
puts "Or enter search if you would like to search for videos."
|
34
|
+
|
35
|
+
input = gets.strip.downcase
|
36
|
+
|
37
|
+
categories_hash = {
|
38
|
+
"top talks" => "1",
|
39
|
+
"technology" => "2",
|
40
|
+
"entertainment" => "3",
|
41
|
+
"design" => "4",
|
42
|
+
"business" => "5",
|
43
|
+
"science" => "6",
|
44
|
+
"global+issues" => "7"
|
45
|
+
}
|
46
|
+
|
47
|
+
if input.to_i == 1
|
48
|
+
list_talks
|
49
|
+
elsif input.to_i > 1 && input.to_i <= 7
|
50
|
+
url_value = categories_hash.key(input)
|
51
|
+
url = "http://www.ted.com/talks?topics%5B%5D=#{url_value}&sort=newest"
|
52
|
+
list_talks(url)
|
53
|
+
elsif categories_hash.key?(input)
|
54
|
+
url_value = input
|
55
|
+
url = "http://www.ted.com/talks?topics%5B%5D=#{url_value}&sort=newest"
|
56
|
+
list_talks(url)
|
57
|
+
elsif input == "search"
|
58
|
+
puts "Enter your search term."
|
59
|
+
url_value = gets.strip.downcase
|
60
|
+
url_value.gsub! /\s+/, '+'
|
61
|
+
url = "http://www.ted.com/talks?q=#{url_value}&sort=newest"
|
62
|
+
list_talks(url)
|
63
|
+
elsif input == "exit"
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def menu
|
70
|
+
input = nil
|
71
|
+
|
72
|
+
while input != "exit"
|
73
|
+
puts " "
|
74
|
+
puts "Enter the number of the talk you'd like to learn more about."
|
75
|
+
puts "Enter talks to see the talks again."
|
76
|
+
puts "Enter categories to see the categories again."
|
77
|
+
puts "Enter exit to end the program."
|
78
|
+
|
79
|
+
input = gets.strip.downcase
|
80
|
+
|
81
|
+
if input.to_i > 0
|
82
|
+
the_talk = @talks[input.to_i - 1]
|
83
|
+
@talk_info = TedTalks::Info.talk_info(the_talk.url)
|
84
|
+
display_talk_info(@talk_info)
|
85
|
+
elsif input == "talks"
|
86
|
+
list_talks
|
87
|
+
elsif input == "categories"
|
88
|
+
list_categories
|
89
|
+
elsif input != "exit"
|
90
|
+
puts "Invalid entry."
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def display_talk_info(talk_info)
|
96
|
+
puts " "
|
97
|
+
puts "------------------TED------------------------"
|
98
|
+
puts talk_info.author
|
99
|
+
puts talk_info.title
|
100
|
+
puts " "
|
101
|
+
puts "-----------------Details---------------------"
|
102
|
+
puts talk_info.description
|
103
|
+
puts " "
|
104
|
+
puts "Time #{talk_info.time} "
|
105
|
+
puts talk_info.date
|
106
|
+
puts " "
|
107
|
+
puts "Total views: #{talk_info.views} "
|
108
|
+
puts "----------------------------------------------"
|
109
|
+
end
|
110
|
+
|
111
|
+
def goodbye
|
112
|
+
puts "See you tomorrow for more talks."
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class TedTalks::Talk
|
2
|
+
|
3
|
+
attr_accessor :title, :author, :date, :rating, :url, :description, :time, :date, :views
|
4
|
+
|
5
|
+
def initialize(title=nil, author=nil, date=nil, rating=nil, url=nil)
|
6
|
+
@title = title
|
7
|
+
@author = author
|
8
|
+
@date = date
|
9
|
+
@rating = rating
|
10
|
+
@@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.top_talks(url='http://www.ted.com/talks')
|
14
|
+
|
15
|
+
talk_array = []
|
16
|
+
|
17
|
+
doc = Nokogiri::HTML(open(url))
|
18
|
+
|
19
|
+
title = doc.css(".media__message").css("h4.h9").css("a")
|
20
|
+
author = doc.css(".media__message").css("h4.h12")
|
21
|
+
date = doc.css(".media__message").css(".meta").css(".meta__item").css("span.meta__val")
|
22
|
+
rating = doc.css(".media__message").css(".meta").css(".meta__row").css(".meta__val")
|
23
|
+
url = doc.css("h4.h9").css("a")
|
24
|
+
|
25
|
+
(0..9).each do |i|
|
26
|
+
|
27
|
+
talk = self.new
|
28
|
+
talk.title = title[i].text.strip! if title[i] != nil
|
29
|
+
talk.author = author[i].text if author[i] != nil
|
30
|
+
talk.date = date[i].text.strip! if date[i] != nil
|
31
|
+
talk.rating = rating[i].text.strip! if rating[i] != nil
|
32
|
+
talk.url = "http://www.ted.com" + url[i].attr("href") if url[i] != nil
|
33
|
+
|
34
|
+
talk_array << talk if talk.title != nil
|
35
|
+
end
|
36
|
+
|
37
|
+
talk_array
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class TedTalks::Info
|
2
|
+
|
3
|
+
attr_accessor :title, :author, :description, :time, :date, :views
|
4
|
+
|
5
|
+
def initialize(title=nil, author=nil, description=nil, time=nil, date=nil, views=nil)
|
6
|
+
@title = title
|
7
|
+
@author = author
|
8
|
+
@description = description
|
9
|
+
@time = time
|
10
|
+
@date = date
|
11
|
+
@@views = views
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.talk_info(url='http://www.ted.com/talks')
|
15
|
+
doc = Nokogiri::HTML(open(url))
|
16
|
+
|
17
|
+
author = doc.search("div.player-hero__speaker").search("span.player-hero__speaker__content")
|
18
|
+
title = doc.search("div.player-hero__title").search("span.player-hero__title__content")
|
19
|
+
description = doc.search(".talk-subsection").search(".talk-top__details").search("p.talk-description")
|
20
|
+
time = doc.search("div.player-hero__meta").search("span")
|
21
|
+
date = doc.search("div.player-hero__meta").search("span")
|
22
|
+
views = doc.search("div.talk-sharing__count").search("span.talk-sharing__value")
|
23
|
+
|
24
|
+
talk_info = self.new
|
25
|
+
talk_info.author = author.text
|
26
|
+
talk_info.title = title.text
|
27
|
+
talk_info.description = description.text
|
28
|
+
talk_info.time = time[0].text
|
29
|
+
talk_info.date = date[1].text
|
30
|
+
talk_info.views = views.text.strip!
|
31
|
+
talk_info
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ted_talks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ted_talks"
|
8
|
+
spec.version = TedTalks::VERSION
|
9
|
+
spec.authors = ["sameera91"]
|
10
|
+
spec.email = ["sameera.bachoti@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem displays information on the latest TED talks.}
|
13
|
+
spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
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 public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "nokogiri"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ted_talks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sameera91
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-04 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: '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: 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: :development
|
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
|
+
- sbachoti91@gmail.com
|
86
|
+
executables:
|
87
|
+
- console
|
88
|
+
- ted_talks
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- NOTES.md
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/ted_talks
|
100
|
+
- lib/ted_talks.rb
|
101
|
+
- lib/ted_talks/cli.rb
|
102
|
+
- lib/ted_talks/talk.rb
|
103
|
+
- lib/ted_talks/talk_info.rb
|
104
|
+
- lib/ted_talks/version.rb
|
105
|
+
- ted_talks-0.1.2.gem
|
106
|
+
- ted_talks.gemspec
|
107
|
+
- ted_talks/.gitignore
|
108
|
+
- ted_talks/.rspec
|
109
|
+
- ted_talks/.travis.yml
|
110
|
+
- ted_talks/CODE_OF_CONDUCT.md
|
111
|
+
- ted_talks/Gemfile
|
112
|
+
- ted_talks/LICENSE.txt
|
113
|
+
- ted_talks/README.md
|
114
|
+
- ted_talks/Rakefile
|
115
|
+
- ted_talks/bin/console
|
116
|
+
- ted_talks/bin/setup
|
117
|
+
- ted_talks/lib/ted_talks.rb
|
118
|
+
- ted_talks/lib/ted_talks/cli.rb
|
119
|
+
- ted_talks/lib/ted_talks/talk.rb
|
120
|
+
- ted_talks/lib/ted_talks/talk_info.rb
|
121
|
+
- ted_talks/lib/ted_talks/version.rb
|
122
|
+
- ted_talks/spec/spec_helper.rb
|
123
|
+
- ted_talks/spec/ted_talks_spec.rb
|
124
|
+
- ted_talks/ted_talks.gemspec
|
125
|
+
homepage: ''
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.6.3
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: This gem displays information on the latest TED talks.
|
149
|
+
test_files: []
|