buapi 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f35190ca5128d6c9d0e73b9fd5c12748e82671d8
4
- data.tar.gz: 9c08274df6aae769b71c77af55f1f66cd2050bcc
3
+ metadata.gz: 9b6303a972cae0589f5396ff3a5588055a352a90
4
+ data.tar.gz: 53fafce8e6ff0b76e5f0221f900a86638b360dae
5
5
  SHA512:
6
- metadata.gz: 0e78840db21c6dba4257f7b8ea91d42067cf69051ea039175507d989e2d3702f75515d96cd3b4614a9d69a63c01b10b28956600134406bf814077542213ee921
7
- data.tar.gz: 5e3810e5c6a6ef6fd5c0ebe63dd2b0939dca04dda6489f046134ceee8f50aadbb808639b9b2155bffaad709003085e000a2487bab3201247f61dd49bf0d6e6dc
6
+ metadata.gz: 9d526c65088d82915479ff0033184e469f33ef64c4c5ec09026548bcd7931485ce7c9c81b4a8db6cbfce7fca19fe93ab1328f3e351cf7e7d11a6e8f310bc5c4f
7
+ data.tar.gz: 39d8498564dc1f372a03a0f93f53013e65e6d5cdf6c9fd19be5b372a32a6ff226db769c481f491d3717e7324643f43ae860f13495d51e57690fd9b6634e9307a
data/lib/bu/api.rb CHANGED
@@ -16,11 +16,16 @@ module BU
16
16
  BU::Dashboard.new(url, doc(url))
17
17
  end
18
18
 
19
- private
20
- def doc(url)
21
- Nokogiri::HTML(@conn.get(url).body)
22
- end
19
+ def scanlators
20
+ url = 'https://www.mangaupdates.com/groups.html'
21
+ BU::Scanlators.new(url, self)
22
+ end
23
23
 
24
+ def doc(url)
25
+ Nokogiri::HTML(@conn.get(url).body)
26
+ end
27
+
28
+ private
24
29
  def search(target, post_options)
25
30
  Nokogiri::HTML(@conn.post(target, post_options).body)
26
31
  end
data/lib/bu/dashboard.rb CHANGED
@@ -13,10 +13,13 @@ module BU
13
13
  title: title,
14
14
  id: id,
15
15
  genres: genres,
16
+ authors: authors,
17
+ artists: artists,
16
18
  description: description,
17
19
  scanlators: scanlators,
18
20
  }
19
21
  end
22
+ alias_method :to_hash, :to_h
20
23
 
21
24
  def to_s
22
25
  to_h.each_with_object('') do |(key,value),out|
@@ -43,9 +46,16 @@ module BU
43
46
  end
44
47
 
45
48
  def genres
46
- info[14].css('a')[0..-2].map {|a| a.text}
49
+ info[14].css('a')[0..-2].map(&:text)
50
+ end
51
+
52
+ def authors
53
+ info[18].css('a').map(&:text)
47
54
  end
48
55
 
56
+ def artists
57
+ info[19].css('a').map(&:text)
58
+ end
49
59
  def scanlators
50
60
  info[4].css('a')
51
61
  .select {|a| a.text != "Less..." && a.text != "More..." }
@@ -0,0 +1,85 @@
1
+ module BU
2
+ class Scanlators
3
+
4
+ attr_reader :url, :doc
5
+ def initialize(url, api, scanlators = nil)
6
+ @url = url
7
+ @api = api
8
+ @doc = @api.doc(url_for_page(1))
9
+ @scanlators = scanlators
10
+ end
11
+
12
+ def count
13
+ @count ||= all.length
14
+ end
15
+
16
+ def all
17
+ scanlators
18
+ end
19
+
20
+ def irc_channels
21
+ scanlators.map { |s| s[:irc] }
22
+ end
23
+
24
+ def with_irc
25
+ @with_irc ||=
26
+ Scanlators.new(url, @api, scanlators.select { |s| s[:irc][0] })
27
+ end
28
+
29
+ def active
30
+ @active ||=
31
+ Scanlators.new(url, @api, scanlators.select { |s| s[:active] })
32
+ end
33
+
34
+ def search(term)
35
+ scanlators.select { |s| s[:name] =~ /#{term}/i }
36
+ end
37
+
38
+ private
39
+ def scanlators
40
+ return @scanlators if @scanlators
41
+
42
+ puts 'Retrieving scanlators...'
43
+ @scanlators = []
44
+ page_numbers.each { |num| scrape_page(num) }
45
+ @scanlators
46
+ end
47
+
48
+ def page_numbers
49
+ last = doc.css('a').find { |a|
50
+ a.text == 'Last' && a[:href].include?("#{url}?page=")
51
+ }[:href].slice(/#{url}\?page=(\d+)/, 1)
52
+ 1..last.to_i
53
+ end
54
+
55
+ def scrape_page(num)
56
+ print "#{num}..."
57
+ page_doc = @api.doc(url_for_page(num))
58
+ scanlator_rows(page_doc).each do |tr|
59
+ cells = tr.css('td')
60
+ link = cells.first.css('a').first
61
+ @scanlators << {
62
+ name: link.text,
63
+ url: link[:href],
64
+ active: !!(cells[1].text =~ /yes/i),
65
+ irc: cells[2].text
66
+ }
67
+ end
68
+ end
69
+
70
+ def scanlator_rows(page_doc)
71
+ page_doc.css('tr').select { |tr|
72
+ tds = tr.children.select { |c| c.name == 'td' }
73
+ if tds.length == 3
74
+ link = tds.first.css('a').first
75
+ link && link[:href].include?("#{url}?id=")
76
+ end
77
+ }
78
+ end
79
+
80
+ def url_for_page(num)
81
+ "#{url}?page=#{num}&perpage=100"
82
+ end
83
+ end
84
+ end
85
+
data/lib/buapi.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'bu/dashboard'
2
+ require_relative 'bu/scanlators'
2
3
  require_relative 'bu/api'
3
4
 
4
5
  module BU
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jphager2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-22 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Useful interface BakaUpdates
14
14
  email: jphager2@gmail.com
@@ -19,6 +19,7 @@ files:
19
19
  - LICENSE
20
20
  - lib/bu/api.rb
21
21
  - lib/bu/dashboard.rb
22
+ - lib/bu/scanlators.rb
22
23
  - lib/buapi.rb
23
24
  - test/lib/bu/api_test.rb
24
25
  - test/lib/bu/dashboard_test.rb
@@ -44,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  version: '0'
45
46
  requirements: []
46
47
  rubyforge_project:
47
- rubygems_version: 2.2.2
48
+ rubygems_version: 2.4.6
48
49
  signing_key:
49
50
  specification_version: 4
50
51
  summary: Useful interface BakaUpdates