wikian 0.1.6 → 0.1.11
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +18 -8
- data/lib/wikian.rb +11 -23
- data/lib/wikian/contributions.rb +48 -0
- data/lib/wikian/get.rb +2 -4
- data/lib/wikian/monkeypatches.rb +24 -0
- data/lib/wikian/post.rb +1 -1
- data/lib/wikian/search.rb +2 -4
- data/lib/wikian/subcommand.rb +3 -4
- data/lib/wikian/version.rb +1 -1
- data/wikian.gemspec +3 -3
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a043e93eb44e9e28a9ce90970196b4ba1c3a07ed485969b699afa2cdad61591
|
4
|
+
data.tar.gz: a848bf0d381a11fd3836cb4eb1557f2681933e182ea84fc2243f0bead9a0840f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 980ee96658d992854345d9a8e411299d6a427358cac77cf1c16d1010140706e296ba44ebac2c266d7eb12cd29635eed5fdf1ab11a102a61b5e9a1f7e651b1708
|
7
|
+
data.tar.gz: 81a4423049990447c690e60b5294fd0566f0d7de631b4f4083ff05ff89fabc20c5912e729e228c692da3764c4425d53cd986d2f157240d16c1df522c8858b737
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Wikian
|
2
2
|
|
3
|
-
Want to be happier
|
4
|
-
|
3
|
+
Want to be a happier [Wikipedian](https://en.wikipedia.org/wiki/Wikipedia:Wikipedians)?
|
4
|
+
Then you want [Wikian](https://rubygems.org/gems/wikian), which lets you edit Wikipedia pages locally, with your favorite text editor.
|
5
|
+
To install it:
|
5
6
|
|
6
7
|
```
|
7
8
|
$ gem install wikian
|
@@ -39,7 +40,7 @@ $ cat User:$WIKI_USER.en.wikitionary.org.wiki
|
|
39
40
|
== Last section==
|
40
41
|
testing
|
41
42
|
|
42
|
-
$ wi post -
|
43
|
+
$ wi post -a User:$WIKI_USER.en.wikitionary.org.wiki
|
43
44
|
Article uploaded
|
44
45
|
```
|
45
46
|
|
@@ -55,7 +56,7 @@ Writing to Wikipedia:Sandbox.en.wikipedia.org.json
|
|
55
56
|
Writing to Wikipedia:Sandbox.en.wikipedia.org.wiki
|
56
57
|
```
|
57
58
|
|
58
|
-
Then edit the
|
59
|
+
Then edit the article and upload it:
|
59
60
|
|
60
61
|
```bash
|
61
62
|
$ wi post Wikipedia:Sandbox.en.wikipedia.org.wiki
|
@@ -69,15 +70,24 @@ $ wi post -s 2 Wikipedia:Sandbox.en.wikipedia.org.wiki
|
|
69
70
|
Article uploaded
|
70
71
|
```
|
71
72
|
|
72
|
-
To search for a pattern in
|
73
|
+
To search for a pattern in Wikipedia:
|
73
74
|
|
74
75
|
```
|
75
76
|
$ wi search -t
|
76
77
|
Creating template wiki.yml
|
77
78
|
|
78
|
-
$ wi
|
79
|
-
|
79
|
+
$ wi s
|
80
|
+
Writing to Mr. Fixit.json
|
81
|
+
```
|
82
|
+
|
83
|
+
To get your last 10 Wikipedia contributions:
|
84
|
+
|
80
85
|
```
|
86
|
+
$ wi c -t
|
87
|
+
Creating template wiki.yml
|
81
88
|
|
82
|
-
|
89
|
+
$ wi c
|
90
|
+
Writing to User:Example_User.contributions.en.wikipedia.org.json
|
91
|
+
```
|
83
92
|
|
93
|
+
Vim users should try [mediawiki.vim](https://en.wikipedia.org/wiki/Help:Text_editor_support#Vim) which adds syntax highlighting and abbreviations for wikitext files.
|
data/lib/wikian.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift __dir__
|
2
2
|
|
3
3
|
require 'wikian/subcommand'
|
4
|
+
require 'wikian/contributions'
|
4
5
|
require 'wikian/get'
|
6
|
+
require 'wikian/monkeypatches'
|
5
7
|
require 'wikian/post'
|
6
8
|
require 'wikian/search'
|
7
9
|
require 'wikian/version'
|
@@ -13,24 +15,6 @@ require 'net/http'
|
|
13
15
|
require 'open-uri'
|
14
16
|
require 'yaml'
|
15
17
|
|
16
|
-
# external libraries
|
17
|
-
require 'byebug'
|
18
|
-
|
19
|
-
class Array
|
20
|
-
# return true if `self` and `elms` have any element in common
|
21
|
-
def have?(elms)
|
22
|
-
(self & elms).length > 0 ? true : false
|
23
|
-
end
|
24
|
-
alias_method :has?, :have?
|
25
|
-
end
|
26
|
-
|
27
|
-
class Hash
|
28
|
-
# return a query string representation of a hash
|
29
|
-
def to_query
|
30
|
-
URI.decode(URI.encode_www_form(self))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
18
|
class Wikian
|
35
19
|
class WikianError < StandardError; end
|
36
20
|
class UnknownSubcommandError < WikianError; end
|
@@ -53,7 +37,7 @@ class Wikian
|
|
53
37
|
|
54
38
|
@subcommand = args.shift
|
55
39
|
|
56
|
-
raise(UnknownSubcommandError, "Unkown Subcommand") unless %w(g p s get post search).include?(subcommand)
|
40
|
+
raise(UnknownSubcommandError, "Unkown Subcommand") unless %w(c g p s contributions get post search).include?(subcommand)
|
57
41
|
|
58
42
|
if subcommand[0] == 'g'
|
59
43
|
api = Wikian::Get.new(args)
|
@@ -62,13 +46,16 @@ class Wikian
|
|
62
46
|
elsif subcommand[0] == 's'
|
63
47
|
api = Wikian::Search.new(args)
|
64
48
|
api.doit
|
49
|
+
elsif subcommand[0] == 'c'
|
50
|
+
api = Wikian::Contributions.new(args)
|
51
|
+
api.doit
|
65
52
|
else
|
66
53
|
api = Wikian::Post.new(args)
|
67
54
|
api.post
|
68
55
|
end
|
69
56
|
|
70
57
|
rescue UnknownSubcommandError => e
|
71
|
-
puts "#{e.class} #{e.message}"
|
58
|
+
puts "#{e.class} #{e.message} in #{__FILE__}"
|
72
59
|
end
|
73
60
|
|
74
61
|
def help
|
@@ -88,9 +75,10 @@ class Wikian
|
|
88
75
|
-v, --version
|
89
76
|
|
90
77
|
Subcommands:
|
91
|
-
|
92
|
-
|
93
|
-
|
78
|
+
c, contributions [N] get user last N contributions. N defaults to 20
|
79
|
+
g, get get wikitext file from a wikipedia article
|
80
|
+
p, post post wikitext file to a wikipedia article
|
81
|
+
s, search search wikitext file to a wikipedia article
|
94
82
|
|
95
83
|
Examples:
|
96
84
|
# create wiki.yml template
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Wikian
|
2
|
+
class WikianGetError < StandardError; end
|
3
|
+
class ExtractWikiError < WikianGetError; end
|
4
|
+
class ArgumentRequiredError < WikianGetError; end
|
5
|
+
|
6
|
+
class Contributions < Subcommand
|
7
|
+
DEFAULT_MAX_CONTRIBUTIONS = 20
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
super
|
11
|
+
|
12
|
+
max_contributions = args.find(&:numeric?) || DEFAULT_MAX_CONTRIBUTIONS
|
13
|
+
|
14
|
+
raise(BadUrlError, "Try passing the '-t' option") unless yaml['meta']['site']
|
15
|
+
|
16
|
+
@output_file = 'User:' + ENV['WIKI_USER'] + '.contributions.' + yaml['meta']['site']
|
17
|
+
|
18
|
+
@params.merge!('ucuser' => ENV['WIKI_USER'], 'uclimit' => max_contributions, 'format' => Wikian::RESPONSE_FORMAT)
|
19
|
+
|
20
|
+
@query = @params.to_query
|
21
|
+
|
22
|
+
@api_url = URI("https://#{yaml['meta']['site']}/w/api.php?#{query}")
|
23
|
+
rescue => e
|
24
|
+
puts "#{e.class} in #{__FILE__}. #{e.message}"
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
def template
|
29
|
+
<<~eos
|
30
|
+
# for a list of parameters to use here see: https://www.mediawiki.org/wiki/API:Usercontribs
|
31
|
+
meta:
|
32
|
+
site: en.wikipedia.org
|
33
|
+
headers:
|
34
|
+
user-agent: Wikian
|
35
|
+
api:
|
36
|
+
action:
|
37
|
+
- query
|
38
|
+
list:
|
39
|
+
- usercontribs
|
40
|
+
ucprop:
|
41
|
+
- title
|
42
|
+
- comment
|
43
|
+
- timestamp
|
44
|
+
- sizediff
|
45
|
+
eos
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/wikian/get.rb
CHANGED
@@ -2,7 +2,6 @@ class Wikian
|
|
2
2
|
class WikianGetError < StandardError; end
|
3
3
|
class ExtractWikiError < WikianGetError; end
|
4
4
|
class ArgumentRequiredError < WikianGetError; end
|
5
|
-
class BadUrlError < WikianGetError; end
|
6
5
|
|
7
6
|
class Get < Subcommand
|
8
7
|
attr_accessor :title
|
@@ -26,7 +25,7 @@ class Wikian
|
|
26
25
|
|
27
26
|
@api_url = URI("https://#{url.host}/w/api.php?#{query}")
|
28
27
|
rescue => e
|
29
|
-
puts "#{e.class} #{
|
28
|
+
puts "#{e.class} in #{__FILE__}. #{e.message}"
|
30
29
|
exit
|
31
30
|
end
|
32
31
|
|
@@ -73,6 +72,7 @@ class Wikian
|
|
73
72
|
|
74
73
|
def template
|
75
74
|
<<~eos
|
75
|
+
# for a list of parameters to use here see: https://www.mediawiki.org/wiki/API:Get_the_contents_of_a_page
|
76
76
|
meta:
|
77
77
|
headers:
|
78
78
|
user-agent: Wikian
|
@@ -90,8 +90,6 @@ class Wikian
|
|
90
90
|
- main
|
91
91
|
formatversion:
|
92
92
|
- 2
|
93
|
-
format:
|
94
|
-
- json
|
95
93
|
eos
|
96
94
|
end
|
97
95
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Array
|
2
|
+
# return true if `self` and `elms` have any element in common
|
3
|
+
def have?(elms)
|
4
|
+
(self & elms).length > 0 ? true : false
|
5
|
+
end
|
6
|
+
alias_method :has?, :have?
|
7
|
+
end
|
8
|
+
|
9
|
+
class Hash
|
10
|
+
# return a query string representation of a hash
|
11
|
+
def to_query
|
12
|
+
URI.decode(URI.encode_www_form(self))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class String
|
17
|
+
# check is a string is numeric
|
18
|
+
#
|
19
|
+
# usage: 'asdf'.numeric? # => false
|
20
|
+
# '5.1'.numeric? # => true
|
21
|
+
def numeric?
|
22
|
+
Float(self) != nil rescue false
|
23
|
+
end
|
24
|
+
end
|
data/lib/wikian/post.rb
CHANGED
data/lib/wikian/search.rb
CHANGED
@@ -14,13 +14,13 @@ class Wikian
|
|
14
14
|
|
15
15
|
@api_url = URI("https://#{yaml['meta']['site']}/w/api.php?#{query}")
|
16
16
|
rescue => e
|
17
|
-
puts "#{e.class} #{
|
17
|
+
puts "#{e.class} in #{__FILE__}. #{e.message}"
|
18
18
|
exit
|
19
19
|
end
|
20
20
|
|
21
21
|
def template
|
22
22
|
<<~eos
|
23
|
-
#
|
23
|
+
# for a list of parameters to use here see: https://www.mediawiki.org/wiki/API:Search
|
24
24
|
meta:
|
25
25
|
site: en.wikipedia.org
|
26
26
|
headers:
|
@@ -32,8 +32,6 @@ class Wikian
|
|
32
32
|
- search
|
33
33
|
srsearch: # text to search for. You can use multiple
|
34
34
|
- Mr. Fixit
|
35
|
-
format:
|
36
|
-
- json
|
37
35
|
eos
|
38
36
|
end
|
39
37
|
end
|
data/lib/wikian/subcommand.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
class Wikian
|
3
3
|
class WikianSubcommandError < StandardError; end
|
4
4
|
class MissingConfigFileError < WikianSubcommandError; end
|
5
|
+
class BadUrlError < WikianSubcommandError; end
|
5
6
|
|
6
7
|
# class to be inherited by other Wikian classes
|
7
8
|
class Subcommand
|
@@ -35,9 +36,7 @@ class Wikian
|
|
35
36
|
(puts 'Bye'; exit) if answer != 'y'
|
36
37
|
end
|
37
38
|
|
38
|
-
File.
|
39
|
-
f.write template
|
40
|
-
end
|
39
|
+
File.write(CONFIG_FILE, template)
|
41
40
|
exit
|
42
41
|
end
|
43
42
|
|
@@ -67,7 +66,7 @@ class Wikian
|
|
67
66
|
|
68
67
|
write_response
|
69
68
|
rescue => e
|
70
|
-
puts "#{e.class} #{
|
69
|
+
puts "#{e.class} in #{__FILE__}. #{e.message}"
|
71
70
|
exit
|
72
71
|
end
|
73
72
|
|
data/lib/wikian/version.rb
CHANGED
data/wikian.gemspec
CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["sergioro"]
|
7
7
|
spec.email = ["yo@sergioro.com"]
|
8
8
|
|
9
|
-
spec.summary = %q{Get and
|
10
|
-
spec.description = %q{Get and
|
11
|
-
|
9
|
+
spec.summary = %q{Get and update Wikipedia articles}
|
10
|
+
spec.description = %q{Get and update Wikipedia articles}
|
11
|
+
spec.homepage = "https://sergioro.mx/posts/wikian"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
14
|
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergioro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Get and
|
13
|
+
description: Get and update Wikipedia articles
|
14
14
|
email:
|
15
15
|
- yo@sergioro.com
|
16
16
|
executables:
|
@@ -32,13 +32,15 @@ files:
|
|
32
32
|
- exe/wikian
|
33
33
|
- lib/.gitignore
|
34
34
|
- lib/wikian.rb
|
35
|
+
- lib/wikian/contributions.rb
|
35
36
|
- lib/wikian/get.rb
|
37
|
+
- lib/wikian/monkeypatches.rb
|
36
38
|
- lib/wikian/post.rb
|
37
39
|
- lib/wikian/search.rb
|
38
40
|
- lib/wikian/subcommand.rb
|
39
41
|
- lib/wikian/version.rb
|
40
42
|
- wikian.gemspec
|
41
|
-
homepage:
|
43
|
+
homepage: https://sergioro.mx/posts/wikian
|
42
44
|
licenses:
|
43
45
|
- MIT
|
44
46
|
metadata: {}
|
@@ -60,5 +62,5 @@ requirements: []
|
|
60
62
|
rubygems_version: 3.1.4
|
61
63
|
signing_key:
|
62
64
|
specification_version: 4
|
63
|
-
summary: Get and
|
65
|
+
summary: Get and update Wikipedia articles
|
64
66
|
test_files: []
|