kizapi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2007-12-31
2
+
3
+ * Keita Yamaguchi:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2007 Keita Yamaguchi
2
+
3
+ ruby-kizapi is released under the Ruby license.
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/kizapi.rb
9
+ lib/kizapi/version.rb
10
+ log/debug.log
11
+ script/destroy
12
+ script/generate
13
+ script/txt2html
14
+ setup.rb
15
+ spec/kizapi_spec.rb
16
+ spec/spec.opts
17
+ spec/spec_helper.rb
18
+ tasks/deployment.rake
19
+ tasks/environment.rake
20
+ tasks/rspec.rake
21
+ tasks/website.rake
22
+ website/index.html
23
+ website/index.txt
24
+ website/javascripts/rounded_corners_lite.inc.js
25
+ website/stylesheets/screen.css
26
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,17 @@
1
+ = README
2
+
3
+ Authors:: Keita Yamaguchi(山口慶太)
4
+ Copyright:: Copyright (C) Keita Yamaguchi, 2007. All rights reserved.
5
+ License:: Ruby License
6
+
7
+ == What
8
+
9
+ ruby-kizapi is a wrapper library for kizAPI provided by kizasi.jp.
10
+
11
+ == Links
12
+
13
+ * {kizasi.jp}[http://kizasi.jp/]
14
+ * {kizAPI}[http://kizasi.jp/tool/kizapi.html]
15
+ * ruby-kizapi
16
+ * {Website}[http://kizapi.rubyforge.org/]
17
+ * {Rubyforge Project}[http://rubyforge.org/projects/kizapi/]
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'kizapi/version'
2
+
3
+ AUTHOR = 'Keita Yamaguchi' # can also be an array of Authors
4
+ EMAIL = "keita.yamaguchi@gmail.com"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'kizapi' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'kizapi' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = KizAPI::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+
36
+ class Hoe
37
+ def extra_deps
38
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
39
+ @extra_deps
40
+ end
41
+ end
42
+
43
+ # Generate all the Rake tasks
44
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
45
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
46
+ p.author = AUTHOR
47
+ p.description = DESCRIPTION
48
+ p.email = EMAIL
49
+ p.summary = DESCRIPTION
50
+ p.url = HOMEPATH
51
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
52
+ p.test_globs = ["test/**/test_*.rb"]
53
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
54
+
55
+ # == Optional
56
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
57
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
58
+
59
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
60
+
61
+ end
62
+
63
+ Rake::RDocTask.new(:docs) do |rd|
64
+ rd.main = "README.txt"
65
+ rd.rdoc_dir = "doc"
66
+ Dir.glob("lib/**/*.rb") do |path| rd.rdoc_files << path end
67
+ rd.rdoc_files += ["README.txt", "History.txt", "License.txt"]
68
+ rd.title = GEM_NAME + " " + VERS + " documentation"
69
+ rd.options += ["--opname", "index.html",
70
+ "--line-numbers",
71
+ "--inline-source",
72
+ "--charset", "UTF-8"]
73
+ end
74
+
75
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
76
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
77
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
78
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'kizapi'
@@ -0,0 +1,9 @@
1
+ module KizAPI #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/kizapi.rb ADDED
@@ -0,0 +1,151 @@
1
+ require "uri"
2
+ require "open-uri"
3
+ require "rss"
4
+ require "time"
5
+
6
+ # import Dublin Core into RSS 2.0
7
+ module RSS
8
+ class Rss
9
+ install_ns(DC_PREFIX, DC_URI)
10
+ class Channel; include DublincoreModel; end
11
+ class Channel::Item; include DublincoreModel; end
12
+ end
13
+ end
14
+
15
+ module KizAPI
16
+
17
+ # RelatedWords is a class for searching related words of a keyword.
18
+ class RelatedWords < Array
19
+ attr_reader :keyword, :span
20
+ # measured time
21
+ attr_reader :date
22
+
23
+ # Make a list of related words of a keyword.
24
+ # keyword:: keyword in UTF-8
25
+ # span:: "24", "1w", or "1m"
26
+ def initialize(keyword, span="24")
27
+ @keyword = keyword
28
+ @span = span
29
+ uri = URI.parse(URI.escape(<<-URL.chomp))
30
+ http://kizasi.jp/kizapi.py?span=#{span}&kw_expr=#{keyword}&type=coll
31
+ URL
32
+ rss = RSS::Parser.parse(uri.read)
33
+ @date = rss.channel.lastBuildDate
34
+ super(rss.items.map{|item| item.title})
35
+ end
36
+
37
+ # Same as RelatedWords.new(keyword, "24").
38
+ def self.day(keyword)
39
+ new(keyword, "24")
40
+ end
41
+
42
+ # Same as RelatedWords.new(keyword, "1w").
43
+ def self.week(keyword)
44
+ new(keyword, "1w")
45
+ end
46
+
47
+ # Same as RelatedWords.new(keyword, "1m").
48
+ def self.month(keyword)
49
+ new(keyword, "1m")
50
+ end
51
+ end
52
+
53
+ # KeyWordInContext is a class for fetching 3 sentences in context including a keyword.
54
+ class KeywordInContexts < Array
55
+ class Context < Array
56
+ attr_reader :title, :link, :date
57
+ def initialize(item)
58
+ @title = item.title
59
+ @date = item.pubDate
60
+ @link = URI.parse(item.link)
61
+ item.description.split("<br>")[0..2].each do |s|
62
+ push s unless /^<ul>/.match(s)
63
+ end
64
+ end
65
+ end
66
+
67
+ attr_reader :date, :keyword
68
+
69
+ # Fetch 3 sentences
70
+ def initialize(keyword)
71
+ @keyword = keyword
72
+ uri = URI.parse(URI.escape(<<-URL.chomp))
73
+ http://kizasi.jp/kizapi.py?kw_expr=#{keyword}&type=kwic
74
+ URL
75
+ rss = RSS::Parser.parse(uri.read)
76
+ @date = rss.channel.lastBuildDate
77
+ super(rss.items.map{|item| Context.new(item)})
78
+ end
79
+ end
80
+
81
+ # KWIC is an alias of KeywordInContext.
82
+ KWIC = KeywordInContexts
83
+
84
+ # Ranking is a class for fetching TOP 30 keywords in kizasi.jp ranking.
85
+ class Ranking < Array
86
+ class Keyword < String
87
+ # URL in kizasi.jp
88
+ attr_reader :link
89
+ def initialize(item)
90
+ super(item.title)
91
+ @link = URI.parse(item.link)
92
+ end
93
+ end
94
+
95
+ # published date
96
+ attr_reader :date
97
+
98
+ def initialize
99
+ uri = URI.parse("http://kizasi.jp/kizapi.py?type=rank")
100
+ rss = RSS::Parser.parse(uri.read)
101
+ @date = rss.channel.lastBuildDate
102
+ super(rss.items.map{|item| Keyword.new(item)})
103
+ end
104
+ end
105
+
106
+ # ChannelWords is a class for fetching co-occurrence channel words of a keyword.
107
+ class ChannelWords < Array
108
+ class Word < String
109
+ attr_reader :subject
110
+ def initialize(item)
111
+ super(item.title)
112
+ @subject = item.dc_subject
113
+ end
114
+ end
115
+
116
+ attr_reader :keyword, :span
117
+
118
+ # published date
119
+ attr_reader :date
120
+
121
+ # Make a list of co-occurrence channel words of a keyword.
122
+ # keyword:: keyword in UTF-8
123
+ # span:: "24", "1w", or "1m"
124
+ def initialize(keyword, span="24")
125
+ @keyword = keyword
126
+ @span = span
127
+ uri = URI.parse(URI.escape(<<-URL.chomp))
128
+ http://kizasi.jp/kizapi.py?span=#{span}&kw_expr=#{keyword}&type=channel
129
+ URL
130
+ rss = RSS::Parser.parse(uri.read, true, false)
131
+ @date = rss.channel.lastBuildDate
132
+ super(rss.items.map{|item| Word.new(item)})
133
+ end
134
+
135
+ # Same as ChannelWords.new(keyword, "24").
136
+ def self.day(keyword)
137
+ new(keyword, "24")
138
+ end
139
+
140
+ # Same as ChannelWords.new(keyword, "1w").
141
+ def self.week(keyword)
142
+ new(keyword, "1w")
143
+ end
144
+
145
+ # Same as ChannelWords.new(keyword, "1m").
146
+ def self.month(keyword)
147
+ new(keyword, "1m")
148
+ end
149
+ end
150
+
151
+ end
data/log/debug.log ADDED
File without changes
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/kizapi/version.rb'
15
+
16
+ version = KizAPI::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/kizapi'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)