consadole_aggregator 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/.gitignore +3 -0
  2. data/Rakefile +32 -0
  3. data/VERSION +1 -0
  4. data/consadole_aggregator.gemspec +182 -0
  5. data/lib/consadole_aggregator.rb +25 -0
  6. data/lib/consadole_aggregator/live.rb +0 -0
  7. data/lib/consadole_aggregator/live/builder.rb +44 -0
  8. data/lib/consadole_aggregator/live/parser.rb +26 -0
  9. data/lib/consadole_aggregator/nikkan_sports.rb +38 -0
  10. data/lib/consadole_aggregator/nikkan_sports/builder.rb +29 -0
  11. data/lib/consadole_aggregator/nikkan_sports/entry.rb +19 -0
  12. data/lib/consadole_aggregator/nikkan_sports/parser.rb +37 -0
  13. data/lib/consadole_aggregator/result +2 -0
  14. data/spec/consadole_aggregator/nikkan_sports_spec.rb +8 -0
  15. data/spec/consadole_aggregator_spec.rb +2 -0
  16. data/spec/spec.opts +1 -0
  17. data/spec/spec_helper.rb +5 -0
  18. data/spec/timeline/s674.html +31 -0
  19. data/spec/timeline/s674.html.1 +33 -0
  20. data/spec/timeline/s674.html.10 +45 -0
  21. data/spec/timeline/s674.html.100 +162 -0
  22. data/spec/timeline/s674.html.101 +162 -0
  23. data/spec/timeline/s674.html.102 +168 -0
  24. data/spec/timeline/s674.html.103 +169 -0
  25. data/spec/timeline/s674.html.104 +169 -0
  26. data/spec/timeline/s674.html.105 +171 -0
  27. data/spec/timeline/s674.html.106 +171 -0
  28. data/spec/timeline/s674.html.107 +171 -0
  29. data/spec/timeline/s674.html.108 +171 -0
  30. data/spec/timeline/s674.html.109 +173 -0
  31. data/spec/timeline/s674.html.11 +49 -0
  32. data/spec/timeline/s674.html.110 +173 -0
  33. data/spec/timeline/s674.html.111 +173 -0
  34. data/spec/timeline/s674.html.112 +173 -0
  35. data/spec/timeline/s674.html.113 +173 -0
  36. data/spec/timeline/s674.html.114 +173 -0
  37. data/spec/timeline/s674.html.115 +173 -0
  38. data/spec/timeline/s674.html.116 +173 -0
  39. data/spec/timeline/s674.html.117 +173 -0
  40. data/spec/timeline/s674.html.118 +173 -0
  41. data/spec/timeline/s674.html.119 +173 -0
  42. data/spec/timeline/s674.html.12 +49 -0
  43. data/spec/timeline/s674.html.120 +173 -0
  44. data/spec/timeline/s674.html.13 +51 -0
  45. data/spec/timeline/s674.html.14 +51 -0
  46. data/spec/timeline/s674.html.15 +53 -0
  47. data/spec/timeline/s674.html.16 +57 -0
  48. data/spec/timeline/s674.html.17 +57 -0
  49. data/spec/timeline/s674.html.18 +57 -0
  50. data/spec/timeline/s674.html.19 +57 -0
  51. data/spec/timeline/s674.html.2 +35 -0
  52. data/spec/timeline/s674.html.20 +59 -0
  53. data/spec/timeline/s674.html.21 +59 -0
  54. data/spec/timeline/s674.html.22 +59 -0
  55. data/spec/timeline/s674.html.23 +63 -0
  56. data/spec/timeline/s674.html.24 +65 -0
  57. data/spec/timeline/s674.html.25 +65 -0
  58. data/spec/timeline/s674.html.26 +65 -0
  59. data/spec/timeline/s674.html.27 +67 -0
  60. data/spec/timeline/s674.html.28 +67 -0
  61. data/spec/timeline/s674.html.29 +67 -0
  62. data/spec/timeline/s674.html.3 +37 -0
  63. data/spec/timeline/s674.html.30 +69 -0
  64. data/spec/timeline/s674.html.31 +71 -0
  65. data/spec/timeline/s674.html.32 +73 -0
  66. data/spec/timeline/s674.html.33 +75 -0
  67. data/spec/timeline/s674.html.34 +77 -0
  68. data/spec/timeline/s674.html.35 +77 -0
  69. data/spec/timeline/s674.html.36 +80 -0
  70. data/spec/timeline/s674.html.37 +82 -0
  71. data/spec/timeline/s674.html.38 +82 -0
  72. data/spec/timeline/s674.html.39 +84 -0
  73. data/spec/timeline/s674.html.4 +39 -0
  74. data/spec/timeline/s674.html.40 +84 -0
  75. data/spec/timeline/s674.html.41 +84 -0
  76. data/spec/timeline/s674.html.42 +84 -0
  77. data/spec/timeline/s674.html.43 +84 -0
  78. data/spec/timeline/s674.html.44 +86 -0
  79. data/spec/timeline/s674.html.45 +88 -0
  80. data/spec/timeline/s674.html.46 +88 -0
  81. data/spec/timeline/s674.html.47 +92 -0
  82. data/spec/timeline/s674.html.48 +92 -0
  83. data/spec/timeline/s674.html.49 +92 -0
  84. data/spec/timeline/s674.html.5 +39 -0
  85. data/spec/timeline/s674.html.50 +92 -0
  86. data/spec/timeline/s674.html.51 +92 -0
  87. data/spec/timeline/s674.html.52 +92 -0
  88. data/spec/timeline/s674.html.53 +92 -0
  89. data/spec/timeline/s674.html.54 +92 -0
  90. data/spec/timeline/s674.html.55 +92 -0
  91. data/spec/timeline/s674.html.56 +92 -0
  92. data/spec/timeline/s674.html.57 +92 -0
  93. data/spec/timeline/s674.html.58 +92 -0
  94. data/spec/timeline/s674.html.59 +95 -0
  95. data/spec/timeline/s674.html.6 +39 -0
  96. data/spec/timeline/s674.html.60 +95 -0
  97. data/spec/timeline/s674.html.61 +95 -0
  98. data/spec/timeline/s674.html.62 +95 -0
  99. data/spec/timeline/s674.html.63 +95 -0
  100. data/spec/timeline/s674.html.64 +99 -0
  101. data/spec/timeline/s674.html.65 +99 -0
  102. data/spec/timeline/s674.html.66 +103 -0
  103. data/spec/timeline/s674.html.67 +103 -0
  104. data/spec/timeline/s674.html.68 +105 -0
  105. data/spec/timeline/s674.html.69 +110 -0
  106. data/spec/timeline/s674.html.7 +41 -0
  107. data/spec/timeline/s674.html.70 +110 -0
  108. data/spec/timeline/s674.html.71 +110 -0
  109. data/spec/timeline/s674.html.72 +110 -0
  110. data/spec/timeline/s674.html.73 +116 -0
  111. data/spec/timeline/s674.html.74 +118 -0
  112. data/spec/timeline/s674.html.75 +120 -0
  113. data/spec/timeline/s674.html.76 +122 -0
  114. data/spec/timeline/s674.html.77 +122 -0
  115. data/spec/timeline/s674.html.78 +122 -0
  116. data/spec/timeline/s674.html.79 +128 -0
  117. data/spec/timeline/s674.html.8 +45 -0
  118. data/spec/timeline/s674.html.80 +130 -0
  119. data/spec/timeline/s674.html.81 +130 -0
  120. data/spec/timeline/s674.html.82 +136 -0
  121. data/spec/timeline/s674.html.83 +136 -0
  122. data/spec/timeline/s674.html.84 +136 -0
  123. data/spec/timeline/s674.html.85 +138 -0
  124. data/spec/timeline/s674.html.86 +141 -0
  125. data/spec/timeline/s674.html.87 +143 -0
  126. data/spec/timeline/s674.html.88 +143 -0
  127. data/spec/timeline/s674.html.89 +145 -0
  128. data/spec/timeline/s674.html.9 +45 -0
  129. data/spec/timeline/s674.html.90 +147 -0
  130. data/spec/timeline/s674.html.91 +147 -0
  131. data/spec/timeline/s674.html.92 +147 -0
  132. data/spec/timeline/s674.html.93 +151 -0
  133. data/spec/timeline/s674.html.94 +151 -0
  134. data/spec/timeline/s674.html.95 +157 -0
  135. data/spec/timeline/s674.html.96 +160 -0
  136. data/spec/timeline/s674.html.97 +162 -0
  137. data/spec/timeline/s674.html.98 +162 -0
  138. data/spec/timeline/s674.html.99 +162 -0
  139. metadata +213 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ data/*
2
+ config/*
3
+ db/*
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'spec/rake/spectask'
5
+ Spec::Rake::SpecTask.new(:spec) do |spec|
6
+ spec.libs << 'lib' << 'spec'
7
+ spec.spec_files = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
11
+ spec.libs << 'lib' << 'spec'
12
+ spec.pattern = 'spec/**/*_spec.rb'
13
+ spec.rcov = true
14
+ end
15
+
16
+ begin
17
+ require 'jeweler'
18
+ Jeweler::Tasks.new do |gemspec|
19
+ gemspec.name = "consadole_aggregator"
20
+ gemspec.summary = "Consadole Sapporo's Information Aggregator"
21
+ gemspec.email = "niku@niku.name"
22
+ gemspec.homepage = "http://github.com/niku/consadole_aggregator"
23
+ gemspec.authors = ["niku"]
24
+ gemspec.required_ruby_version = '~>1.9.1'
25
+ gemspec.add_development_dependency(['nokogiri','dm-core','dm-types','dm-validations'])
26
+ gemspec.add_development_dependency('rspec')
27
+ end
28
+ rescue LoadError
29
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
30
+ end
31
+
32
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,182 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{consadole_aggregator}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["niku"]
12
+ s.date = %q{2009-12-21}
13
+ s.email = %q{niku@niku.name}
14
+ s.files = [
15
+ ".gitignore",
16
+ "Rakefile",
17
+ "VERSION",
18
+ "consadole_aggregator.gemspec",
19
+ "lib/consadole_aggregator.rb",
20
+ "lib/consadole_aggregator/live.rb",
21
+ "lib/consadole_aggregator/live/builder.rb",
22
+ "lib/consadole_aggregator/live/parser.rb",
23
+ "lib/consadole_aggregator/nikkan_sports.rb",
24
+ "lib/consadole_aggregator/nikkan_sports/builder.rb",
25
+ "lib/consadole_aggregator/nikkan_sports/entry.rb",
26
+ "lib/consadole_aggregator/nikkan_sports/parser.rb",
27
+ "lib/consadole_aggregator/result",
28
+ "spec/consadole_aggregator/nikkan_sports_spec.rb",
29
+ "spec/consadole_aggregator_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb",
32
+ "spec/timeline/s674.html",
33
+ "spec/timeline/s674.html.1",
34
+ "spec/timeline/s674.html.10",
35
+ "spec/timeline/s674.html.100",
36
+ "spec/timeline/s674.html.101",
37
+ "spec/timeline/s674.html.102",
38
+ "spec/timeline/s674.html.103",
39
+ "spec/timeline/s674.html.104",
40
+ "spec/timeline/s674.html.105",
41
+ "spec/timeline/s674.html.106",
42
+ "spec/timeline/s674.html.107",
43
+ "spec/timeline/s674.html.108",
44
+ "spec/timeline/s674.html.109",
45
+ "spec/timeline/s674.html.11",
46
+ "spec/timeline/s674.html.110",
47
+ "spec/timeline/s674.html.111",
48
+ "spec/timeline/s674.html.112",
49
+ "spec/timeline/s674.html.113",
50
+ "spec/timeline/s674.html.114",
51
+ "spec/timeline/s674.html.115",
52
+ "spec/timeline/s674.html.116",
53
+ "spec/timeline/s674.html.117",
54
+ "spec/timeline/s674.html.118",
55
+ "spec/timeline/s674.html.119",
56
+ "spec/timeline/s674.html.12",
57
+ "spec/timeline/s674.html.120",
58
+ "spec/timeline/s674.html.13",
59
+ "spec/timeline/s674.html.14",
60
+ "spec/timeline/s674.html.15",
61
+ "spec/timeline/s674.html.16",
62
+ "spec/timeline/s674.html.17",
63
+ "spec/timeline/s674.html.18",
64
+ "spec/timeline/s674.html.19",
65
+ "spec/timeline/s674.html.2",
66
+ "spec/timeline/s674.html.20",
67
+ "spec/timeline/s674.html.21",
68
+ "spec/timeline/s674.html.22",
69
+ "spec/timeline/s674.html.23",
70
+ "spec/timeline/s674.html.24",
71
+ "spec/timeline/s674.html.25",
72
+ "spec/timeline/s674.html.26",
73
+ "spec/timeline/s674.html.27",
74
+ "spec/timeline/s674.html.28",
75
+ "spec/timeline/s674.html.29",
76
+ "spec/timeline/s674.html.3",
77
+ "spec/timeline/s674.html.30",
78
+ "spec/timeline/s674.html.31",
79
+ "spec/timeline/s674.html.32",
80
+ "spec/timeline/s674.html.33",
81
+ "spec/timeline/s674.html.34",
82
+ "spec/timeline/s674.html.35",
83
+ "spec/timeline/s674.html.36",
84
+ "spec/timeline/s674.html.37",
85
+ "spec/timeline/s674.html.38",
86
+ "spec/timeline/s674.html.39",
87
+ "spec/timeline/s674.html.4",
88
+ "spec/timeline/s674.html.40",
89
+ "spec/timeline/s674.html.41",
90
+ "spec/timeline/s674.html.42",
91
+ "spec/timeline/s674.html.43",
92
+ "spec/timeline/s674.html.44",
93
+ "spec/timeline/s674.html.45",
94
+ "spec/timeline/s674.html.46",
95
+ "spec/timeline/s674.html.47",
96
+ "spec/timeline/s674.html.48",
97
+ "spec/timeline/s674.html.49",
98
+ "spec/timeline/s674.html.5",
99
+ "spec/timeline/s674.html.50",
100
+ "spec/timeline/s674.html.51",
101
+ "spec/timeline/s674.html.52",
102
+ "spec/timeline/s674.html.53",
103
+ "spec/timeline/s674.html.54",
104
+ "spec/timeline/s674.html.55",
105
+ "spec/timeline/s674.html.56",
106
+ "spec/timeline/s674.html.57",
107
+ "spec/timeline/s674.html.58",
108
+ "spec/timeline/s674.html.59",
109
+ "spec/timeline/s674.html.6",
110
+ "spec/timeline/s674.html.60",
111
+ "spec/timeline/s674.html.61",
112
+ "spec/timeline/s674.html.62",
113
+ "spec/timeline/s674.html.63",
114
+ "spec/timeline/s674.html.64",
115
+ "spec/timeline/s674.html.65",
116
+ "spec/timeline/s674.html.66",
117
+ "spec/timeline/s674.html.67",
118
+ "spec/timeline/s674.html.68",
119
+ "spec/timeline/s674.html.69",
120
+ "spec/timeline/s674.html.7",
121
+ "spec/timeline/s674.html.70",
122
+ "spec/timeline/s674.html.71",
123
+ "spec/timeline/s674.html.72",
124
+ "spec/timeline/s674.html.73",
125
+ "spec/timeline/s674.html.74",
126
+ "spec/timeline/s674.html.75",
127
+ "spec/timeline/s674.html.76",
128
+ "spec/timeline/s674.html.77",
129
+ "spec/timeline/s674.html.78",
130
+ "spec/timeline/s674.html.79",
131
+ "spec/timeline/s674.html.8",
132
+ "spec/timeline/s674.html.80",
133
+ "spec/timeline/s674.html.81",
134
+ "spec/timeline/s674.html.82",
135
+ "spec/timeline/s674.html.83",
136
+ "spec/timeline/s674.html.84",
137
+ "spec/timeline/s674.html.85",
138
+ "spec/timeline/s674.html.86",
139
+ "spec/timeline/s674.html.87",
140
+ "spec/timeline/s674.html.88",
141
+ "spec/timeline/s674.html.89",
142
+ "spec/timeline/s674.html.9",
143
+ "spec/timeline/s674.html.90",
144
+ "spec/timeline/s674.html.91",
145
+ "spec/timeline/s674.html.92",
146
+ "spec/timeline/s674.html.93",
147
+ "spec/timeline/s674.html.94",
148
+ "spec/timeline/s674.html.95",
149
+ "spec/timeline/s674.html.96",
150
+ "spec/timeline/s674.html.97",
151
+ "spec/timeline/s674.html.98",
152
+ "spec/timeline/s674.html.99"
153
+ ]
154
+ s.homepage = %q{http://github.com/niku/consadole_aggregator}
155
+ s.rdoc_options = ["--charset=UTF-8"]
156
+ s.require_paths = ["lib"]
157
+ s.required_ruby_version = Gem::Requirement.new("~> 1.9.1")
158
+ s.rubygems_version = %q{1.3.5}
159
+ s.summary = %q{Consadole Sapporo's Information Aggregator}
160
+ s.test_files = [
161
+ "spec/consadole_aggregator/nikkan_sports_spec.rb",
162
+ "spec/consadole_aggregator_spec.rb",
163
+ "spec/spec_helper.rb"
164
+ ]
165
+
166
+ if s.respond_to? :specification_version then
167
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
168
+ s.specification_version = 3
169
+
170
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
171
+ s.add_development_dependency(%q<["nokogiri", "dm-core", "dm-types", "dm-validations"]>, [">= 0"])
172
+ s.add_development_dependency(%q<rspec>, [">= 0"])
173
+ else
174
+ s.add_dependency(%q<["nokogiri", "dm-core", "dm-types", "dm-validations"]>, [">= 0"])
175
+ s.add_dependency(%q<rspec>, [">= 0"])
176
+ end
177
+ else
178
+ s.add_dependency(%q<["nokogiri", "dm-core", "dm-types", "dm-validations"]>, [">= 0"])
179
+ s.add_dependency(%q<rspec>, [">= 0"])
180
+ end
181
+ end
182
+
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'logger'
3
+
4
+ require 'consadole_aggregator/nikkan_sports'
5
+ require 'consadole_aggregator/live'
6
+
7
+ module ConsadoleAggregator
8
+ def self.log
9
+ @@log ||= Logger.new('log/application.log')
10
+ end
11
+
12
+ Image = Struct.new :src, :alt do
13
+ def to_html
14
+ %Q{<image src="#{self.src}" alt="#{self.alt}">}
15
+ end
16
+ end
17
+ end
18
+
19
+ if __FILE__ == $0
20
+ DataMapper.setup(:default, 'sqlite3:db/test.sqlite3')
21
+ DataMapper.auto_migrate!
22
+
23
+ ConsadoleAggregator::NikkanSports.save
24
+ print ConsadoleAggregator::NikkanSports.rss
25
+ end
File without changes
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'twitter'
3
+
4
+ module ConsadoleAggregator
5
+ module Live
6
+ module Builder
7
+ class Twit
8
+ def initialize
9
+ Process.daemon(true, false)
10
+ @client = Twitter::Client.from_config('config/account.yaml')
11
+ @posted = []
12
+ end
13
+
14
+ def post
15
+ new_line.each do |line|
16
+ @client.status(:post, "#{line.time} #{line.post} #consadole")
17
+ @posted << line
18
+ end
19
+ end
20
+
21
+ def reserve start_time
22
+ start = Time.parse start_time
23
+ ConsadoleAggregator::log.info("#{start.to_time}くらいにはじめる予定")
24
+ sleep start - Time.now
25
+
26
+ live
27
+ end
28
+
29
+ def live
30
+ # サッカーはハーフタイム含めて120分位あれば終わる
31
+ 120.times do
32
+ post
33
+ sleep 60
34
+ end
35
+ end
36
+
37
+ private
38
+ def new_line
39
+ ConsadoleAggregator::Live::Parser.parse - @posted
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'net/http'
3
+ require 'kconv'
4
+
5
+ module ConsadoleAggregator
6
+ module Live
7
+ module Parser
8
+ BASE_URI = URI.parse('http://www.consadole-sapporo.jp/view/s674.html')
9
+ TimeLine = Struct.new :time, :post do
10
+ def initialize line
11
+ tmp = line.split
12
+ self['time'] = tmp[0]
13
+ self['post'] = tmp[1]
14
+ end
15
+ end
16
+
17
+ def Parser.parse
18
+ response = Net::HTTP.get(BASE_URI).force_encoding("Shift_JIS")
19
+ doc = Nokogiri::HTML.parse(response.toutf8, nil, 'UTF-8')
20
+ doc.search('hr + p').last.inner_html.gsub(/<br>/,'').split("\n").map{ |line|
21
+ TimeLine.new line unless /&lt;前半&gt;|&lt;後半&gt;/ =~ line
22
+ }.compact.reverse
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'net/http'
3
+ require 'kconv'
4
+
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+
8
+ require 'consadole_aggregator/nikkan_sports/entry'
9
+ require 'consadole_aggregator/nikkan_sports/parser'
10
+ require 'consadole_aggregator/nikkan_sports/builder'
11
+
12
+ module ConsadoleAggregator
13
+ module NikkanSports
14
+ def NikkanSports.list
15
+ doc = Nokogiri::HTML.parse(Net::HTTP.get(Parser::List::BASE_URI), nil, 'UTF-8')
16
+ Parser::List.parse doc
17
+ end
18
+
19
+ def NikkanSports.save
20
+ NikkanSports.list.map(&:uri).each do |uri|
21
+ doc = Nokogiri::HTML.parse(Net::HTTP.get(uri), nil, 'UTF-8').at('div#news')
22
+ entry = Parser::Entry.parse doc, uri
23
+ entry.save # DataMapper だと 一意制約違反でも例外にならない。ただ挿入できないだけ。
24
+ end
25
+ end
26
+
27
+ def NikkanSports.rss
28
+ entries = Entry.all(:order => [:post_date.desc], :limit => 20)
29
+
30
+ Builder::Rss.build entries do |item, entry|
31
+ item.link = entry.uri.to_s.toutf8
32
+ item.title = entry.title.toutf8
33
+ item.summary = "<div>#{entry.image ? entry.image.to_html + entry.text : entry.text}</div>".toutf8
34
+ item.date = entry.post_date
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rss'
3
+
4
+ module ConsadoleAggregator
5
+ module NikkanSports
6
+ module Builder
7
+ module Rss
8
+ def Rss.build entries
9
+ RSS::Maker.make('atom') do |maker|
10
+ maker.channel.about = 'http://sirase.ru/consadole/nikkansports_consadole.rdf'
11
+ maker.channel.title = 'コンサドーレ札幌:nikkansports.com(非公式RSS版)'
12
+ maker.channel.description = 'コンサドーレ札幌:nikkansports.comのニュース一覧(非公式RSS版)'
13
+ maker.channel.link = 'http://www.nikkansports.com/soccer/jleague/team/co-team.html'
14
+ maker.channel.author = 'ConsadoleAggregator'
15
+ maker.channel.date = Time.now
16
+
17
+ maker.items.do_sort = true
18
+
19
+ entries.each do |entry|
20
+ maker.items.new_item do |item|
21
+ yield item, entry
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'dm-core'
3
+ require 'dm-types'
4
+ require 'dm-validations'
5
+
6
+ module ConsadoleAggregator
7
+ module NikkanSports
8
+ class Entry
9
+ include DataMapper::Resource
10
+
11
+ property :id, Serial
12
+ property :uri, URI, :unique => true
13
+ property :title, String
14
+ property :text, Text
15
+ property :post_date, Time
16
+ property :image, String
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ module ConsadoleAggregator
3
+ module NikkanSports
4
+ module Parser
5
+ module List
6
+ BASE_URI = URI.parse('http://www.nikkansports.com/soccer/jleague/team/co-team.html')
7
+
8
+ Element = Struct.new :uri, :title, :post_date, :has_image? do
9
+ def initialize element
10
+ self['uri'] = URI.parse(element.at('a')['href'])
11
+ self['title'] = element.at('a').text
12
+ self['post_date'] = Time.strptime(element.at('span').text.match(/\d+日\d+:\d+/).to_s, '%d日%H:%M')
13
+ self['has_image?'] = !element.at('img').nil?
14
+ end
15
+ end
16
+
17
+ def List.parse doc
18
+ doc.search('div#topNewsInner ul.newsList01 li').map{|element| Element.new element}
19
+ end
20
+ end
21
+
22
+ module Entry
23
+ IMAGE_BASE_URI = URI.parse('http://cache2.nipc.jp/soccer/news/')
24
+
25
+ def Entry.parse doc, uri = nil
26
+ entry = NikkanSports::Entry.new
27
+ entry.uri = uri if uri
28
+ entry.title = doc.at('h1').text
29
+ entry.text = doc.search('p')[0...-1].to_s
30
+ entry.post_date = Time.strptime(doc.search('p').last.text.match(/\d+年\d+月\d+日\d+時\d+分/).to_s, '%Y年%m月%d日%H時%M分')
31
+ entry.image = Image.new(IMAGE_BASE_URI + image['src'].sub(/\.jpg$/, '-big.jpg'), image['alt']) unless doc.at('img').nil?
32
+ return entry
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end