berklee-valencia 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/berklee-valencia +2 -2
- data/config/environment.rb +4 -12
- data/lib/berklee_valencia.rb +0 -1
- data/lib/berklee_valencia/category.rb +4 -5
- data/lib/berklee_valencia/cli.rb +43 -44
- data/lib/berklee_valencia/formatter.rb +44 -27
- data/lib/berklee_valencia/printer.rb +19 -20
- data/lib/berklee_valencia/program.rb +7 -6
- data/lib/berklee_valencia/scraper.rb +19 -22
- data/lib/berklee_valencia/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c48bdb68e6a29bd188073d0788a71b4bf943983b1b9558fa4f143f85f6c5e735
|
4
|
+
data.tar.gz: 1a597db768565282bf7f205ce6ca887fbcff6bb1901e528cbd1b73024a807399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc127b52a598c66dacd15c926dcdaa82a8c23540e0a080a96a329e64996e7d9ea9b6ca6a1b55c1fa0b2825ab8e86b51f9bdd1763a6c2cc19074216ae9d56bd70
|
7
|
+
data.tar.gz: 63874aaad8ac760e927625589c1d89fefb46bbb2c8aff4723696c9e211c74bf2725ca929ff22a5a6f2223c8cb71aa2dda1639c4e9761de2dd8cdad8f58a6cd48
|
data/bin/berklee-valencia
CHANGED
data/config/environment.rb
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
|
-
require
|
4
|
-
|
5
|
-
# require_relative "../lib/berklee_valencia/version.rb"
|
6
|
-
# require_relative '../lib/berklee_valencia/cli.rb'
|
7
|
-
# require_relative '../lib/berklee_valencia/scraper.rb'
|
8
|
-
# require_relative '../lib/berklee_valencia/news_article.rb'
|
9
|
-
# require_relative '../lib/berklee_valencia/program.rb'
|
10
|
-
# require_relative '../lib/berklee_valencia/printer.rb'
|
11
|
-
# require_relative '../lib/berklee_valencia/formatter.rb'
|
12
|
-
# require_relative '../lib/berklee_valencia/printer.rb'
|
13
|
-
# require_relative '../lib/berklee_valencia/news_article.rb'
|
3
|
+
require 'open_uri_redirections'
|
4
|
+
require 'pry'
|
14
5
|
|
15
|
-
|
6
|
+
|
7
|
+
require_relative '../lib/berklee_valencia/version.rb'
|
16
8
|
require_relative '../lib/berklee_valencia/cli.rb'
|
17
9
|
require_relative '../lib/berklee_valencia/scraper.rb'
|
18
10
|
require_relative '../lib/berklee_valencia/item.rb'
|
data/lib/berklee_valencia.rb
CHANGED
@@ -6,6 +6,7 @@ class BerkleeValencia::CATEGORY
|
|
6
6
|
def initialize(title)
|
7
7
|
@title = title
|
8
8
|
@articles = []
|
9
|
+
self.i = @@all.length + 1
|
9
10
|
@@all << self
|
10
11
|
end
|
11
12
|
|
@@ -17,20 +18,18 @@ class BerkleeValencia::CATEGORY
|
|
17
18
|
if find_by_title(article.category)
|
18
19
|
find_by_title(article.category).articles << article
|
19
20
|
else
|
20
|
-
self.new(article.category).
|
21
|
+
self.new(article.category).articles << article
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def self.find_cat_by_index(input)
|
25
26
|
all.detect{|cat| cat.i == input.to_i}
|
27
|
+
# Any point in changing to all[input.to_i - 1] ?
|
26
28
|
end
|
27
29
|
|
28
30
|
def find_article_by_index(input)
|
29
31
|
@articles.detect{|article| article.i == input.to_i}
|
30
|
-
|
31
|
-
|
32
|
-
def self.index_categories
|
33
|
-
@@all.each.with_index(1) {|cat, i| cat.i = i}
|
32
|
+
# Any point in changing @articles[input.to_i - 1] ?
|
34
33
|
end
|
35
34
|
|
36
35
|
def index_articles
|
data/lib/berklee_valencia/cli.rb
CHANGED
@@ -46,36 +46,6 @@ class BerkleeValencia::CLI
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def list_programs
|
50
|
-
if BerkleeValencia::PROGRAM.all == []
|
51
|
-
BerkleeValencia::SCRAPER.make_programs
|
52
|
-
end
|
53
|
-
puts ""
|
54
|
-
puts "----------------------------------------------------------------"
|
55
|
-
puts " Enter the number of the program you'd like to read more about"
|
56
|
-
puts " or type 'news' to browse our latest news and articles."
|
57
|
-
puts "----------------------------------------------------------------"
|
58
|
-
BerkleeValencia::PRINTER.print_programs_list
|
59
|
-
input = gets.strip.downcase
|
60
|
-
if input.to_i.between?(1,BerkleeValencia::PROGRAM.all.length)
|
61
|
-
show_program(input)
|
62
|
-
elsif input == "news"
|
63
|
-
list_article_categories
|
64
|
-
else
|
65
|
-
if_not_that_then_this(input)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def show_program(input)
|
70
|
-
program = BerkleeValencia::PROGRAM.find_by_index(input.to_i)
|
71
|
-
if !program.introduction
|
72
|
-
attributes = BerkleeValencia::SCRAPER.get_program_extended_info(program.url)
|
73
|
-
program.extended_info_from_scraper(attributes)
|
74
|
-
end
|
75
|
-
BerkleeValencia::PRINTER.print_program(program)
|
76
|
-
what_next
|
77
|
-
end
|
78
|
-
|
79
49
|
def list_article_categories
|
80
50
|
if BerkleeValencia::ARTICLE.all == []
|
81
51
|
BerkleeValencia::SCRAPER.make_articles
|
@@ -85,7 +55,6 @@ class BerkleeValencia::CLI
|
|
85
55
|
puts " Which kind of article are you interested in?"
|
86
56
|
puts " Type 'programs' to browse programs instead"
|
87
57
|
puts "----------------------------------------------"
|
88
|
-
BerkleeValencia::CATEGORY.index_categories
|
89
58
|
BerkleeValencia::PRINTER.print_article_categories
|
90
59
|
input = gets.strip.downcase
|
91
60
|
if input.to_i.between?(1,BerkleeValencia::CATEGORY.all.length)
|
@@ -124,28 +93,46 @@ class BerkleeValencia::CLI
|
|
124
93
|
what_next
|
125
94
|
end
|
126
95
|
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
puts " ... ... ..."
|
96
|
+
def list_programs
|
97
|
+
if BerkleeValencia::PROGRAM.all == []
|
98
|
+
BerkleeValencia::SCRAPER.make_programs
|
99
|
+
end
|
132
100
|
puts ""
|
101
|
+
puts "----------------------------------------------------------------"
|
102
|
+
puts " Enter the number of the program you'd like to read more about"
|
103
|
+
puts " or type 'news' to browse our latest news and articles."
|
104
|
+
puts "----------------------------------------------------------------"
|
105
|
+
BerkleeValencia::PRINTER.print_programs_list
|
106
|
+
input = gets.strip.downcase
|
107
|
+
if input.to_i.between?(1,BerkleeValencia::PROGRAM.all.length)
|
108
|
+
show_program(input)
|
109
|
+
elsif input == "news"
|
110
|
+
list_article_categories
|
111
|
+
else
|
112
|
+
if_not_that_then_this(input)
|
113
|
+
end
|
133
114
|
end
|
134
115
|
|
135
|
-
def
|
116
|
+
def show_program(input)
|
117
|
+
program = BerkleeValencia::PROGRAM.find_by_index(input.to_i)
|
118
|
+
if !program.introduction
|
119
|
+
attributes = BerkleeValencia::SCRAPER.get_program_extended_info(program.url)
|
120
|
+
program.extended_info_from_scraper(attributes)
|
121
|
+
end
|
122
|
+
BerkleeValencia::PRINTER.print_program(program)
|
123
|
+
what_next
|
124
|
+
end
|
125
|
+
|
126
|
+
def please_wait
|
136
127
|
puts ""
|
137
|
-
puts "
|
138
|
-
puts "1. See news articles"
|
139
|
-
puts "2. See programs"
|
128
|
+
puts " Please be patient whilst we get up to date with all our news!"
|
140
129
|
puts ""
|
141
|
-
puts "
|
142
|
-
puts " see you next time with the latest news from Berklee Valencia!"
|
130
|
+
puts " ... ... ..."
|
143
131
|
puts ""
|
144
|
-
programs_or_news
|
145
132
|
end
|
146
133
|
|
147
134
|
def if_not_that_then_this(input)
|
148
|
-
if input.match(/
|
135
|
+
if input.match(/ta luego|exit|bye|ciao/)
|
149
136
|
goodbye
|
150
137
|
elsif input == "menu"
|
151
138
|
menu
|
@@ -160,6 +147,18 @@ class BerkleeValencia::CLI
|
|
160
147
|
what_next
|
161
148
|
end
|
162
149
|
|
150
|
+
def what_next
|
151
|
+
puts ""
|
152
|
+
puts "What would you like to do next?"
|
153
|
+
puts "1. See news articles"
|
154
|
+
puts "2. See programs"
|
155
|
+
puts ""
|
156
|
+
puts " If you're all set, you can just say ciao for now and we will "
|
157
|
+
puts " see you next time with the latest news from Berklee Valencia!"
|
158
|
+
puts ""
|
159
|
+
programs_or_news
|
160
|
+
end
|
161
|
+
|
163
162
|
def goodbye
|
164
163
|
puts ""
|
165
164
|
puts "Hasta luego!"
|
@@ -4,6 +4,10 @@ class Formatter
|
|
4
4
|
text.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
|
5
5
|
end
|
6
6
|
|
7
|
+
def self.urlwrap(text, width=80)
|
8
|
+
text.gsub(/(.{1,#{width}})/, "\\1\n")
|
9
|
+
end
|
10
|
+
|
7
11
|
class Formatter::FORMATARTICLE < Formatter
|
8
12
|
def self.header(article)
|
9
13
|
border = border_maker(article)
|
@@ -17,25 +21,15 @@ class Formatter
|
|
17
21
|
|
18
22
|
def self.border_maker(article)
|
19
23
|
border = ""
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
elsif article.title.length > 80
|
24
|
-
80.times {border << "-"}
|
25
|
-
else
|
26
|
-
borderlength = article.title.length
|
27
|
-
borderlength.times {border << "-"}
|
28
|
-
end
|
24
|
+
bordertestlength = [article.title.length, (article.author.length + article.date.length + 5)].max
|
25
|
+
borderlength = [bordertestlength, 80].min
|
26
|
+
borderlength.times {border << "-"}
|
29
27
|
border
|
30
28
|
end
|
31
29
|
|
32
30
|
def self.gap_maker(article, border)
|
33
31
|
gap = ""
|
34
|
-
|
35
|
-
5.times {gap << " "}
|
36
|
-
else
|
37
|
-
(article.title.length - article.author.length - article.date.length).times {gap << " "}
|
38
|
-
end
|
32
|
+
(border.length - article.author.length - article.date.length).times {gap << " "}
|
39
33
|
gap
|
40
34
|
end
|
41
35
|
|
@@ -44,19 +38,17 @@ class Formatter
|
|
44
38
|
if paragraph.match(/-{3} /)
|
45
39
|
puts " ______________________________________________________________________________"
|
46
40
|
puts " || Press enter to scroll to the next section ||"
|
47
|
-
puts " ||
|
41
|
+
puts " || or type 'end' to skip to end of article. ||"
|
48
42
|
puts " ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
|
49
43
|
input = gets.strip
|
50
|
-
if input == "
|
51
|
-
return "
|
44
|
+
if input == "end"
|
45
|
+
return "end"
|
52
46
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
puts " Vist #{article.related_links.shift}"
|
59
|
-
puts paragraph
|
47
|
+
puts "#{wrap(paragraph)}"
|
48
|
+
puts ""
|
49
|
+
elsif !paragraph.match(/click here/i) && !paragraph.match(/•/)
|
50
|
+
if paragraph.match(/below:/) || paragraph.match(/^Watch|^Listen/)
|
51
|
+
media_compiler(article, paragraph)
|
60
52
|
else
|
61
53
|
puts "#{wrap(paragraph)}"
|
62
54
|
puts ""
|
@@ -65,12 +57,33 @@ class Formatter
|
|
65
57
|
end #do
|
66
58
|
end #print_body method
|
67
59
|
|
68
|
-
def self.
|
60
|
+
def self.media_compiler(article, paragraph)
|
61
|
+
if paragraph.match(/below:/)
|
62
|
+
puts " - - - - - - - - - - - - - - - - - Media - - - - - - - - - - - - - - - - - - -"
|
63
|
+
puts "#{wrap(paragraph)}"
|
64
|
+
puts "#{urlwrap(" Visit #{(article.related_links.shift)}")}"
|
65
|
+
puts "#{urlwrap(" Visit #{(article.related_links.shift)}")}"
|
66
|
+
puts " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
67
|
+
elsif paragraph.match(/watch|listen/i) && paragraph.match(/:\s?\z/)
|
68
|
+
puts " - - - - - - - - - - - - - - - - - Media - - - - - - - - - - - - - - - - - - -"
|
69
|
+
puts "#{wrap(paragraph)}"
|
70
|
+
puts "#{urlwrap(" Visit #{(article.related_links.shift)}")}"
|
71
|
+
puts " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.end(article)
|
69
76
|
puts ""
|
70
77
|
puts " ______________________________________________________________________________"
|
71
|
-
puts " ||
|
78
|
+
puts " || END OF ARTICLE ||"
|
79
|
+
puts " || Type 'open' to see full article in browser ||"
|
80
|
+
puts " || or hit enter to see all options ||"
|
72
81
|
puts " ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
|
73
82
|
2.times {puts ""}
|
83
|
+
input = gets.strip
|
84
|
+
if input == "open"
|
85
|
+
system("open #{article.url}")
|
86
|
+
end
|
74
87
|
end
|
75
88
|
end #class
|
76
89
|
|
@@ -107,9 +120,13 @@ class Formatter
|
|
107
120
|
puts "--------------------------------------------------------------------------------"
|
108
121
|
puts " For full program information:"
|
109
122
|
puts "--------------------------------------------------------------------------------"
|
110
|
-
puts "
|
123
|
+
puts "Type 'open' to visit program homepage or hit enter to see more options."
|
111
124
|
2.times {puts "--------------------------------------------------------------------------------"}
|
112
125
|
2.times {puts ""}
|
126
|
+
input = gets.strip
|
127
|
+
if input == "open"
|
128
|
+
system("open #{program.url}")
|
129
|
+
end
|
113
130
|
end
|
114
131
|
|
115
132
|
end #Program class
|
@@ -1,4 +1,23 @@
|
|
1
1
|
class BerkleeValencia::PRINTER
|
2
|
+
def self.print_article_categories
|
3
|
+
BerkleeValencia::CATEGORY.all.each {|cat| puts "#{cat.i}. #{cat.title}"}
|
4
|
+
puts ""
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.print_articles_list(category)
|
8
|
+
category.articles.each do |article|
|
9
|
+
puts "#{article.i}: #{Formatter.wrap(article.title)}"
|
10
|
+
puts " // Posted on #{article.date}"
|
11
|
+
puts "#{Formatter.wrap(article.excerpt)}"
|
12
|
+
puts ""
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.print_article(article)
|
17
|
+
Formatter::FORMATARTICLE.header(article)
|
18
|
+
Formatter::FORMATARTICLE.body(article)
|
19
|
+
Formatter::FORMATARTICLE.end(article)
|
20
|
+
end
|
2
21
|
|
3
22
|
def self.print_programs_list
|
4
23
|
puts "Graduate Programs"
|
@@ -30,24 +49,4 @@ class BerkleeValencia::PRINTER
|
|
30
49
|
Formatter::FORMATPROGRAM.more_info(program)
|
31
50
|
end
|
32
51
|
|
33
|
-
def self.print_article_categories
|
34
|
-
BerkleeValencia::CATEGORY.all.each {|cat| puts "#{cat.i}. #{cat.title}"}
|
35
|
-
puts ""
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.print_articles_list(category)
|
39
|
-
category.articles.each do |article|
|
40
|
-
puts "#{article.i}: #{Formatter.wrap(article.title)}"
|
41
|
-
puts " // Posted on #{article.date}"
|
42
|
-
puts "#{Formatter.wrap(article.excerpt)}"
|
43
|
-
puts ""
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.print_article(article)
|
48
|
-
Formatter::FORMATARTICLE.header(article)
|
49
|
-
Formatter::FORMATARTICLE.body(article)
|
50
|
-
Formatter::FORMATARTICLE.end
|
51
|
-
end
|
52
|
-
|
53
52
|
end
|
@@ -5,12 +5,13 @@ class BerkleeValencia::PROGRAM < BerkleeValencia::ITEM
|
|
5
5
|
@@other_programs = []
|
6
6
|
|
7
7
|
def self.new_from_scraper(attribute_hash)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
BerkleeValencia::PROGRAM.new(attribute_hash[:title], attribute_hash[:url]).tap do |program|
|
9
|
+
program.type = attribute_hash[:type]
|
10
|
+
program.subtitle = attribute_hash[:subtitle]
|
11
|
+
program.i = @@all.length + 1
|
12
|
+
@@all << program
|
13
|
+
program.type == "Graduate Programs" ? @@graduate_programs << program : @@other_programs << program
|
14
|
+
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def extended_info_from_scraper(attribute_hash)
|
@@ -2,21 +2,6 @@ class BerkleeValencia::SCRAPER
|
|
2
2
|
@@bv_news = "https://valencia.berklee.edu/news/"
|
3
3
|
@@bv_programs = "https://valencia.berklee.edu/academic-programs/"
|
4
4
|
|
5
|
-
def self.make_programs
|
6
|
-
course_types = Nokogiri::HTML(open(@@bv_programs, :allow_redirections => :all)).css("div.col-3-5")
|
7
|
-
course_types.each do |type|
|
8
|
-
type.css("ul a").each do |program|
|
9
|
-
attributes = {
|
10
|
-
title: program.text,
|
11
|
-
subtitle: program.css("span").text,
|
12
|
-
url: program.attribute("href").value,
|
13
|
-
type: type.css("h4").text
|
14
|
-
}
|
15
|
-
BerkleeValencia::PROGRAM.new_from_scraper(attributes)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
5
|
def self.make_articles
|
21
6
|
articles = Nokogiri::HTML(open(@@bv_news, :allow_redirections => :all))
|
22
7
|
articles.css("div#news_container div.content").each do |article|
|
@@ -42,6 +27,22 @@ class BerkleeValencia::SCRAPER
|
|
42
27
|
extended_info
|
43
28
|
end
|
44
29
|
|
30
|
+
def self.make_programs
|
31
|
+
course_types = Nokogiri::HTML(open(@@bv_programs, :allow_redirections => :all)).css("div.col-3-5")
|
32
|
+
course_types.each do |type|
|
33
|
+
type.css("ul a").each do |program|
|
34
|
+
attributes = {
|
35
|
+
title: program.text,
|
36
|
+
subtitle: program.css("span").text,
|
37
|
+
url: program.attribute("href").value,
|
38
|
+
type: type.css("h4").text
|
39
|
+
}
|
40
|
+
BerkleeValencia::PROGRAM.new_from_scraper(attributes)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
45
46
|
def self.get_program_extended_info(url)
|
46
47
|
program = Nokogiri::HTML(open(url, :allow_redirections => :all))
|
47
48
|
extended_info = {
|
@@ -55,17 +56,13 @@ class BerkleeValencia::SCRAPER
|
|
55
56
|
|
56
57
|
def self.sort_content(article, extended_info)
|
57
58
|
article.css("div#tab_intro p").each do |para|
|
58
|
-
if para.css("iframe").length == 0 && para.css("
|
59
|
+
if para.css("iframe").length == 0 && para.css("strong").text == ""
|
59
60
|
extended_info[:body] << para.text
|
60
61
|
elsif para.css("strong").text != ""
|
61
62
|
extended_info[:body] << " --- #{para.text} ---"
|
62
|
-
elsif para.css("em").text != ""
|
63
|
-
comment = "#{para.text}"
|
64
|
-
extended_info[:body] << " - - - - - - - - - - - - - - - - - Media - - - - - - - - - - - - - - - - - - -"
|
65
|
-
extended_info[:body] << comment
|
66
|
-
extended_info[:body] << " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
67
63
|
elsif para.css("iframe").length > 0
|
68
|
-
|
64
|
+
extended_info[:body] << para.text
|
65
|
+
extended_info[:related_links] << para.css("iframe").attribute("src").value
|
69
66
|
end
|
70
67
|
end
|
71
68
|
extended_info
|