askwiki 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/README.md +40 -0
  4. data/askwiki.gemspec +14 -0
  5. data/bin/askwiki +10 -0
  6. data/lib/askwiki.rb +30 -0
  7. metadata +50 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adfb38c4310ee7de917ad2075952f2a00c1ecce9
4
+ data.tar.gz: 59eb6d7560885d77a0d51632f9a457959448d901
5
+ SHA512:
6
+ metadata.gz: 25b32c30b10ef2f67b107a87f8fee1847788b0b544d151b3baeee913477220d4e0e8d8500e3131f908fac2ed5cf0b00b13614b36fe763255a3c3f483a109c2ec
7
+ data.tar.gz: 92490fbd50a9dafa46fecb4f4ea01ff8b03391adc00ff96c42f8589d9da19ebfc72e96e2bc74e58c772bcb314c9bcaf295105fa4758cd19b3636ba9202c91128
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ doc
4
+ Gemfile.lock
5
+ github-test.rb
6
+ pkg
7
+ profile*.html
8
+ rdoc
9
+ *.sqlite3
10
+ *.gem
@@ -0,0 +1,40 @@
1
+ # Ask Wikipedia
2
+
3
+ Ask Wikipedia is a ruby gem for querying wikipedia in any language from within your
4
+ ruby or rails application, and also could be used from commandline directly.
5
+
6
+
7
+ ## Installation
8
+
9
+ you can install latest version using
10
+
11
+ ```ruby
12
+ gem install askwiki
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ add it to your project using
18
+
19
+ ```ruby
20
+ require 'askwiki'
21
+ # instantiate a new object and ask it
22
+ obj = Askwiki.new('en') # padd wikipedia language as param or leave it for english
23
+ print obj.ask('API') # to ask wikipedia for an article
24
+
25
+ # or use the class method
26
+ print Askwiki.ask('API')
27
+ ```
28
+
29
+ also you can use it from commandline/terminal as follows
30
+
31
+ ```bash
32
+ $ askwiki API
33
+ ```
34
+ ## Questions and Problems ?
35
+
36
+ open a new issue to let me know and i will response as soon as possible
37
+
38
+ ## How to Help
39
+
40
+ we appreciate Star/Fork/Watch on github so show love, and if you wanna help more then fork, then add a feature or enhance it, and send me a pull request, i will review and merge your commit.
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'askwiki'
3
+ s.version = '0.1.0'
4
+ s.summary = 'ask wikipedia from cli'
5
+ s.description = 'get article text from wikipedia from cli'
6
+ s.authors = ['Emad Elsaid']
7
+ s.email = ['blazeeboy@gmail.com']
8
+ s.files = `git ls-files`.split("\n").sort
9
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ s.platform = Gem::Platform::RUBY
11
+ s.homepage = 'http://www.github.com/user/repo'
12
+ s.license = 'MIT'
13
+ s.require_paths = ['lib']
14
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'askwiki'
3
+
4
+ query = ARGV[0] ||
5
+ begin
6
+ print 'What do you need to know? : '
7
+ gets.chomp
8
+ end
9
+
10
+ puts Askwiki.ask(query)
@@ -0,0 +1,30 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ class Askwiki
5
+ @language
6
+
7
+
8
+ def initialize( lang='en' )
9
+ @language = lang
10
+ end
11
+
12
+ def ask query
13
+ query_encoded = URI::encode(query)
14
+ request_url = "http://#{@language}.wikipedia.org/w/api.php?action=parse&page=#{query_encoded}&format=json&prop=text&section=0&redirects"
15
+
16
+ open(request_url) do |file|
17
+ puts JSON.parse(file.read())['parse']['text'].first[1]
18
+ .gsub(/<\/?[^>]+>/, '') # strip tags
19
+ .gsub(/[[:space:]]+/, ' ') # strip whitespace
20
+ .gsub(/&#[0-9]+;/,'') # strip encoded
21
+ .gsub(/\[[0-9]+\]/,'') # strip referencing
22
+ end
23
+ end
24
+
25
+ def self.ask( query, lang='en' )
26
+ ask_obj = Askwiki.new lang
27
+ ask_obj.ask query
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: askwiki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emad Elsaid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: get article text from wikipedia from cli
14
+ email:
15
+ - blazeeboy@gmail.com
16
+ executables:
17
+ - askwiki
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - README.md
23
+ - askwiki.gemspec
24
+ - bin/askwiki
25
+ - lib/askwiki.rb
26
+ homepage: http://www.github.com/user/repo
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.2.2
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: ask wikipedia from cli
50
+ test_files: []