wikiscript 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/HISTORY.md +3 -3
- data/Manifest.txt +10 -7
- data/README.md +17 -1
- data/Rakefile +30 -30
- data/lib/wikiscript.rb +37 -36
- data/lib/wikiscript/client.rb +63 -62
- data/lib/wikiscript/page.rb +28 -0
- data/lib/wikiscript/version.rb +5 -4
- data/test/helper.rb +13 -0
- data/test/test_austria.rb +24 -0
- metadata +23 -25
- checksums.yaml +0 -7
data/.gemtest
ADDED
File without changes
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
### 0.0.1 / 2014-07-03
|
2
|
-
|
3
|
-
* Everything is new. First release.
|
1
|
+
### 0.0.1 / 2014-07-03
|
2
|
+
|
3
|
+
* Everything is new. First release.
|
data/Manifest.txt
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
HISTORY.md
|
2
|
-
Manifest.txt
|
3
|
-
README.md
|
4
|
-
Rakefile
|
5
|
-
lib/wikiscript.rb
|
6
|
-
lib/wikiscript/client.rb
|
7
|
-
lib/wikiscript/
|
1
|
+
HISTORY.md
|
2
|
+
Manifest.txt
|
3
|
+
README.md
|
4
|
+
Rakefile
|
5
|
+
lib/wikiscript.rb
|
6
|
+
lib/wikiscript/client.rb
|
7
|
+
lib/wikiscript/page.rb
|
8
|
+
lib/wikiscript/version.rb
|
9
|
+
test/helper.rb
|
10
|
+
test/test_austria.rb
|
data/README.md
CHANGED
@@ -8,7 +8,18 @@
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
Read-only access to wikikpedia pages.
|
12
|
+
Example - Get wikitext source (via `en.wikipedia.org/w/index.php?action=raw&title=<title>`):
|
13
|
+
|
14
|
+
|
15
|
+
>> page = Wikiscript::Page.new( '2014_FIFA_World_Cup_squads' )
|
16
|
+
>> page.text
|
17
|
+
|
18
|
+
The [[2014 FIFA World Cup]] is an international [[association football|football]]
|
19
|
+
tournament which is currently being held in Brazil from 12 June to 13 July 2014.
|
20
|
+
The 32 national teams involved in the tournament were required to register
|
21
|
+
a squad of 23 players, including three goalkeepers...
|
22
|
+
|
12
23
|
|
13
24
|
## Install
|
14
25
|
|
@@ -17,6 +28,11 @@ Just install the gem:
|
|
17
28
|
$ gem install wikiscript
|
18
29
|
|
19
30
|
|
31
|
+
## Alternatives
|
32
|
+
|
33
|
+
TBD
|
34
|
+
|
35
|
+
|
20
36
|
## License
|
21
37
|
|
22
38
|
The `wikiscript` scripts are dedicated to the public domain.
|
data/Rakefile
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
require 'hoe'
|
2
|
-
require './lib/wikiscript/version.rb'
|
3
|
-
|
4
|
-
Hoe.spec 'wikiscript' do
|
5
|
-
|
6
|
-
self.version = Wikiscript::VERSION
|
7
|
-
|
8
|
-
self.summary = 'wikiscript - scripts for wikipedia (get wikitext for page etc.)'
|
9
|
-
self.description = summary
|
10
|
-
|
11
|
-
self.urls = ['https://github.com/wikiscript/wikiscript.ruby']
|
12
|
-
|
13
|
-
self.author = 'Gerald Bauer'
|
14
|
-
self.email = 'opensport@googlegroups.com'
|
15
|
-
|
16
|
-
# switch extension to .markdown for gihub formatting
|
17
|
-
self.readme_file = 'README.md'
|
18
|
-
self.history_file = 'HISTORY.md'
|
19
|
-
|
20
|
-
self.extra_deps = [
|
21
|
-
['logutils' ]
|
22
|
-
]
|
23
|
-
|
24
|
-
self.licenses = ['Public Domain']
|
25
|
-
|
26
|
-
self.spec_extras = {
|
27
|
-
:required_ruby_version => '>= 1.9.2'
|
28
|
-
}
|
29
|
-
|
30
|
-
end
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/wikiscript/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'wikiscript' do
|
5
|
+
|
6
|
+
self.version = Wikiscript::VERSION
|
7
|
+
|
8
|
+
self.summary = 'wikiscript - scripts for wikipedia (get wikitext for page etc.)'
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = ['https://github.com/wikiscript/wikiscript.ruby']
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'opensport@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'HISTORY.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['logutils' ]
|
22
|
+
]
|
23
|
+
|
24
|
+
self.licenses = ['Public Domain']
|
25
|
+
|
26
|
+
self.spec_extras = {
|
27
|
+
:required_ruby_version => '>= 1.9.2'
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
data/lib/wikiscript.rb
CHANGED
@@ -1,36 +1,37 @@
|
|
1
|
-
## stdlibs
|
2
|
-
|
3
|
-
require 'net/http'
|
4
|
-
require 'uri'
|
5
|
-
require 'json'
|
6
|
-
require 'pp'
|
7
|
-
require 'ostruct'
|
8
|
-
|
9
|
-
|
10
|
-
## 3rd party gems/libs
|
11
|
-
## require 'props'
|
12
|
-
|
13
|
-
require 'logutils'
|
14
|
-
|
15
|
-
|
16
|
-
# our own code
|
17
|
-
|
18
|
-
require 'wikiscript/version' # let it always go first
|
19
|
-
require 'wikiscript/client'
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
1
|
+
## stdlibs
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
require 'pp'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
|
10
|
+
## 3rd party gems/libs
|
11
|
+
## require 'props'
|
12
|
+
|
13
|
+
require 'logutils'
|
14
|
+
|
15
|
+
|
16
|
+
# our own code
|
17
|
+
|
18
|
+
require 'wikiscript/version' # let it always go first
|
19
|
+
require 'wikiscript/client'
|
20
|
+
require 'wikiscript/page'
|
21
|
+
|
22
|
+
|
23
|
+
module Wikiscript
|
24
|
+
|
25
|
+
def self.banner
|
26
|
+
"wikiscript/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.root
|
30
|
+
"#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
|
31
|
+
end
|
32
|
+
|
33
|
+
end # module Wikiscript
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
puts Wikiscript.banner
|
data/lib/wikiscript/client.rb
CHANGED
@@ -1,62 +1,63 @@
|
|
1
|
-
|
2
|
-
module Wikiscript
|
3
|
-
|
4
|
-
class Client
|
5
|
-
|
6
|
-
include LogUtils::Logging
|
7
|
-
|
8
|
-
SITE_BASE = 'http://en.wikipedia.org/w/index.php'
|
9
|
-
|
10
|
-
### API_BASE = 'http://en.wikipedia.org/w/api.php'
|
11
|
-
|
12
|
-
def initialize( opts={} )
|
13
|
-
@opts = opts
|
14
|
-
end
|
15
|
-
|
16
|
-
def text( title )
|
17
|
-
## todo/fix: urlencode title ???
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
proxy
|
31
|
-
proxy = ENV['
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
t
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end #
|
1
|
+
|
2
|
+
module Wikiscript
|
3
|
+
|
4
|
+
class Client
|
5
|
+
|
6
|
+
include LogUtils::Logging
|
7
|
+
|
8
|
+
SITE_BASE = 'http://en.wikipedia.org/w/index.php'
|
9
|
+
|
10
|
+
### API_BASE = 'http://en.wikipedia.org/w/api.php'
|
11
|
+
|
12
|
+
def initialize( opts={} )
|
13
|
+
@opts = opts
|
14
|
+
end
|
15
|
+
|
16
|
+
def text( title )
|
17
|
+
## todo/fix: urlencode title ???
|
18
|
+
## fix: use params hash!!!
|
19
|
+
get( "action=raw&title=#{title}" )
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
### fix: reuse code from fetcher gem!!!!
|
24
|
+
## do NOT duplicate!!! also cleanup jogo gem!!!!
|
25
|
+
|
26
|
+
def get( params )
|
27
|
+
uri = URI.parse( "#{SITE_BASE}?#{params}" )
|
28
|
+
|
29
|
+
|
30
|
+
# new code: honor proxy env variable HTTP_PROXY
|
31
|
+
proxy = ENV['HTTP_PROXY']
|
32
|
+
proxy = ENV['http_proxy'] if proxy.nil? # try possible lower/case env variable (for *nix systems) is this necessary??
|
33
|
+
|
34
|
+
if proxy
|
35
|
+
proxy = URI.parse( proxy )
|
36
|
+
logger.debug "using net http proxy: proxy.host=#{proxy.host}, proxy.port=#{proxy.port}"
|
37
|
+
if proxy.user && proxy.password
|
38
|
+
logger.debug " using credentials: proxy.user=#{proxy.user}, proxy.password=****"
|
39
|
+
else
|
40
|
+
logger.debug " using no credentials"
|
41
|
+
end
|
42
|
+
else
|
43
|
+
logger.debug "using direct net http access; no proxy configured"
|
44
|
+
proxy = OpenStruct.new # all fields return nil (e.g. proxy.host, etc.)
|
45
|
+
end
|
46
|
+
|
47
|
+
http_proxy = Net::HTTP::Proxy( proxy.host, proxy.port, proxy.user, proxy.password )
|
48
|
+
|
49
|
+
http = http_proxy.new( uri.host, uri.port )
|
50
|
+
response = http.request( Net::HTTP::Get.new( uri.request_uri ))
|
51
|
+
|
52
|
+
if response.code == '200'
|
53
|
+
t = response.body
|
54
|
+
## pp t
|
55
|
+
t
|
56
|
+
else
|
57
|
+
logger.error "fetch HTTP - #{response.code} #{response.message}"
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end # class Client
|
63
|
+
end # Wikiscript
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module Wikiscript
|
3
|
+
|
4
|
+
class Page
|
5
|
+
|
6
|
+
include LogUtils::Logging
|
7
|
+
|
8
|
+
attr_reader :title, :text
|
9
|
+
|
10
|
+
def initialize( title )
|
11
|
+
## todo: check title
|
12
|
+
## replace title spaces w/ _ ????
|
13
|
+
## to allow "pretty" titles - why? why not??
|
14
|
+
|
15
|
+
@title = title
|
16
|
+
@text = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def text
|
20
|
+
if @text.nil?
|
21
|
+
# cache text (from request)
|
22
|
+
@text = Client.new.text( @title )
|
23
|
+
end
|
24
|
+
@text
|
25
|
+
end
|
26
|
+
|
27
|
+
end # class Page
|
28
|
+
end # Wikiscript
|
data/lib/wikiscript/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
2
|
-
module Wikiscript
|
3
|
-
VERSION = '0.0
|
4
|
-
end
|
1
|
+
|
2
|
+
module Wikiscript
|
3
|
+
VERSION = '0.1.0'
|
4
|
+
end
|
5
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## $:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
## minitest setup
|
4
|
+
|
5
|
+
# require 'minitest/unit'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
# include MiniTest::Unit # lets us use TestCase instead of MiniTest::Unit::TestCase
|
9
|
+
|
10
|
+
## our own code
|
11
|
+
|
12
|
+
require 'wikiscript'
|
13
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
require 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestAustria < MiniTest::Unit::TestCase
|
8
|
+
|
9
|
+
def test_text
|
10
|
+
page = Wikiscript::Page.new( 'Austria' )
|
11
|
+
text = page.text
|
12
|
+
|
13
|
+
## print first 600 chars
|
14
|
+
pp text[0..600]
|
15
|
+
|
16
|
+
## check for some snippets
|
17
|
+
assert( /{{Infobox country/ =~ text )
|
18
|
+
assert( /common_name = Austria/ =~ text )
|
19
|
+
assert( /capital = \[\[Vienna\]\]/ =~ text )
|
20
|
+
assert( /The origins of modern-day Austria date back to the time/ =~ text )
|
21
|
+
end
|
22
|
+
|
23
|
+
end # class TestAustria
|
24
|
+
|
metadata
CHANGED
@@ -1,57 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikiscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Gerald Bauer
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: logutils
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &73243800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
|
-
version_requirements:
|
23
|
-
requirements:
|
24
|
-
- - ! '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
24
|
+
version_requirements: *73243800
|
27
25
|
- !ruby/object:Gem::Dependency
|
28
26
|
name: rdoc
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &73243290 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
30
29
|
requirements:
|
31
30
|
- - ~>
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '4.0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '4.0'
|
35
|
+
version_requirements: *73243290
|
41
36
|
- !ruby/object:Gem::Dependency
|
42
37
|
name: hoe
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &73242780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
44
40
|
requirements:
|
45
41
|
- - ~>
|
46
42
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
43
|
+
version: '3.11'
|
48
44
|
type: :development
|
49
45
|
prerelease: false
|
50
|
-
version_requirements:
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.10'
|
46
|
+
version_requirements: *73242780
|
55
47
|
description: wikiscript - scripts for wikipedia (get wikitext for page etc.)
|
56
48
|
email: opensport@googlegroups.com
|
57
49
|
executables: []
|
@@ -67,11 +59,14 @@ files:
|
|
67
59
|
- Rakefile
|
68
60
|
- lib/wikiscript.rb
|
69
61
|
- lib/wikiscript/client.rb
|
62
|
+
- lib/wikiscript/page.rb
|
70
63
|
- lib/wikiscript/version.rb
|
64
|
+
- test/helper.rb
|
65
|
+
- test/test_austria.rb
|
66
|
+
- .gemtest
|
71
67
|
homepage: https://github.com/wikiscript/wikiscript.ruby
|
72
68
|
licenses:
|
73
69
|
- Public Domain
|
74
|
-
metadata: {}
|
75
70
|
post_install_message:
|
76
71
|
rdoc_options:
|
77
72
|
- --main
|
@@ -79,19 +74,22 @@ rdoc_options:
|
|
79
74
|
require_paths:
|
80
75
|
- lib
|
81
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
82
78
|
requirements:
|
83
79
|
- - ! '>='
|
84
80
|
- !ruby/object:Gem::Version
|
85
81
|
version: 1.9.2
|
86
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
87
84
|
requirements:
|
88
85
|
- - ! '>='
|
89
86
|
- !ruby/object:Gem::Version
|
90
87
|
version: '0'
|
91
88
|
requirements: []
|
92
89
|
rubyforge_project:
|
93
|
-
rubygems_version:
|
90
|
+
rubygems_version: 1.8.17
|
94
91
|
signing_key:
|
95
|
-
specification_version:
|
92
|
+
specification_version: 3
|
96
93
|
summary: wikiscript - scripts for wikipedia (get wikitext for page etc.)
|
97
|
-
test_files:
|
94
|
+
test_files:
|
95
|
+
- test/test_austria.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 4fd62d114d9a91fc66c7ab7ff876c483b8f56492
|
4
|
-
data.tar.gz: 3035ff53b83b8cb4d110b1be3046adb6adb89f46
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: a580bfa164a812dded6a2d267fde47dfdf413bb2f587e9ce72d7b68af8af483be3ecd4e8d9036b3c4a54c11d41228c2808eba2d2076cffffb1ae766ba90b9e9b
|
7
|
-
data.tar.gz: 8cd5d6104a444cf9ce2edf904275d2a14fdd9c423806c1ccebc2dd7ee0b59d7cd866c96ec609ddb5fde208f06a02961df521135de37f739745869b5dc816a239
|