wikian 0.1.1 → 0.1.6
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/.gitignore +1 -18
- data/Gemfile.lock +1 -1
- data/README.md +40 -19
- data/lib/wikian.rb +8 -0
- data/lib/wikian/get.rb +7 -5
- data/lib/wikian/post.rb +5 -2
- data/lib/wikian/search.rb +2 -2
- data/lib/wikian/subcommand.rb +7 -0
- data/lib/wikian/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e066880739b70e35ea72420c4692f03b06edb3e166de62e4266c2fb0ed987361
|
4
|
+
data.tar.gz: 2844bbad116737e2325e917670bb2e91820ccc8f6d4304cf1f84e826832cc0b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '065693de9893b9741bd4b6cc3ee86c66ae7c7d9406acede75cedc78dba156351f0412ce187aed004325ebd7e9c0bdb1bada66ffabf9df158b304ec2f6d178c26'
|
7
|
+
data.tar.gz: 50feea8fa794dfe9b53acce2cbd161bd641a6407df241c5c69ebcacfe6a5930ed9be2e68f37911d82455d143526d4ae14ce3da577b374d36b09ab725f8b77dd4
|
data/.gitignore
CHANGED
@@ -1,15 +1,6 @@
|
|
1
|
-
# files without extensions except directories
|
2
|
-
*
|
3
|
-
!/**/
|
4
|
-
!?*.*
|
5
|
-
|
6
1
|
# directories
|
7
|
-
.bundle/
|
8
|
-
_yardoc/
|
9
|
-
coverage/
|
10
2
|
doc/
|
11
3
|
pkg/
|
12
|
-
spec/reports/
|
13
4
|
tmp/
|
14
5
|
vendor/
|
15
6
|
|
@@ -22,6 +13,7 @@ vendor/
|
|
22
13
|
.*.swp
|
23
14
|
.DS_Store
|
24
15
|
.byebug
|
16
|
+
.byebugrc
|
25
17
|
.idea
|
26
18
|
.project
|
27
19
|
.rake*
|
@@ -46,12 +38,3 @@ secrets.yml
|
|
46
38
|
![MR]akefile
|
47
39
|
!bin/**/[^.]*
|
48
40
|
!exe/**/[^.]*
|
49
|
-
|
50
|
-
/.bundle/
|
51
|
-
/.yardoc
|
52
|
-
/_yardoc/
|
53
|
-
/coverage/
|
54
|
-
/doc/
|
55
|
-
/pkg/
|
56
|
-
/spec/reports/
|
57
|
-
/tmp/
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
# Wikian
|
2
2
|
|
3
3
|
Want to be happier while editing wiki files?
|
4
|
-
|
4
|
+
Me too, that's why I use [Wikian](https://rubygems.org/gems/wikian):
|
5
5
|
|
6
6
|
```
|
7
7
|
$ gem install wikian
|
8
8
|
```
|
9
9
|
|
10
|
-
To use it
|
11
|
-
Then define and export the `WIKI_USER` and `SECRET_WIKI_PASS` variables in your `.bashrc`:
|
10
|
+
To use it create a Wikipedia account, then define and export the `WIKI_USER` and `SECRET_WIKI_PASS` variables in your `.bashrc`:
|
12
11
|
|
13
12
|
```bash
|
14
|
-
export WIKI_USER='
|
15
|
-
export SECRET_WIKI_PASS='
|
13
|
+
export WIKI_USER='Example_wiki_user_name'
|
14
|
+
export SECRET_WIKI_PASS='example_wiki_password'
|
16
15
|
```
|
17
16
|
|
18
|
-
Wikian works across [Wikimedia sites](https://meta.wikimedia.org/wiki/Our_projects)
|
19
|
-
Create a file following the convention:
|
17
|
+
Wikian works across [Wikimedia sites](https://meta.wikimedia.org/wiki/Our_projects) and follows the file naming convention:
|
20
18
|
|
21
19
|
```
|
22
20
|
<article_name>.<site>.wiki
|
23
21
|
```
|
24
22
|
|
25
|
-
|
23
|
+
Some valid file names:
|
24
|
+
|
25
|
+
```
|
26
|
+
Spider_Man.en.wikipedia.org.wiki
|
27
|
+
Spider_Man.es.wikipedia.org.wiki
|
28
|
+
excelsior.es.wiktionary.org.wiki
|
29
|
+
User:Example_User.www.mediawiki.org.wiki
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Examples
|
26
33
|
|
27
34
|
To append some text to your Wiktionary user profile:
|
28
35
|
|
@@ -36,27 +43,41 @@ $ wi post -p User:$WIKI_USER.en.wikitionary.org.wiki
|
|
36
43
|
Article uploaded
|
37
44
|
```
|
38
45
|
|
39
|
-
To
|
40
|
-
Generate a template `wiki.yml` config:
|
46
|
+
To get an article's wikitext:
|
41
47
|
|
42
|
-
```
|
43
|
-
wi g -t
|
44
|
-
```
|
45
48
|
|
46
|
-
|
49
|
+
```
|
50
|
+
$ wi get -t
|
51
|
+
Creating template wiki.yml
|
47
52
|
|
48
|
-
|
49
|
-
$ wi get https://en.wikipedia.org/wiki/Wikipedia:Sandbox
|
53
|
+
$ wi g https://en.wikipedia.org/wiki/Wikipedia:Sandbox
|
50
54
|
Writing to Wikipedia:Sandbox.en.wikipedia.org.json
|
51
55
|
Writing to Wikipedia:Sandbox.en.wikipedia.org.wiki
|
52
56
|
```
|
53
57
|
|
54
|
-
|
55
|
-
When ready, uploaded it:
|
58
|
+
Then edit the the article in your favorite text editor and upload it:
|
56
59
|
|
57
60
|
```bash
|
58
61
|
$ wi post Wikipedia:Sandbox.en.wikipedia.org.wiki
|
59
62
|
Article uploaded
|
60
63
|
```
|
61
64
|
|
62
|
-
|
65
|
+
To append wikitext to section 2:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
$ wi post -s 2 Wikipedia:Sandbox.en.wikipedia.org.wiki
|
69
|
+
Article uploaded
|
70
|
+
```
|
71
|
+
|
72
|
+
To search for a pattern in wikipedia:
|
73
|
+
|
74
|
+
```
|
75
|
+
$ wi search -t
|
76
|
+
Creating template wiki.yml
|
77
|
+
|
78
|
+
$ wi search
|
79
|
+
Article uploaded
|
80
|
+
```
|
81
|
+
|
82
|
+
Vim users should try out [mediawiki.vim](https://en.wikipedia.org/wiki/Help:Text_editor_support#Vim) which defines syntax highlighting and abbreviations for wikitext files.
|
83
|
+
|
data/lib/wikian.rb
CHANGED
@@ -47,6 +47,8 @@ class Wikian
|
|
47
47
|
def run
|
48
48
|
if args.have?(%w(-h --help))
|
49
49
|
help
|
50
|
+
elsif args.have?(%w(-v --version))
|
51
|
+
version
|
50
52
|
end
|
51
53
|
|
52
54
|
@subcommand = args.shift
|
@@ -81,6 +83,7 @@ class Wikian
|
|
81
83
|
-m, --message MESSAGE add a commit message (HIGHLY recommended)
|
82
84
|
-p, --prepend prepend the input file
|
83
85
|
-r, --remove-cookie remove API cookie
|
86
|
+
-s, --section NUMBER section to edit
|
84
87
|
-t, --template create template configuration file
|
85
88
|
-v, --version
|
86
89
|
|
@@ -119,4 +122,9 @@ class Wikian
|
|
119
122
|
eos
|
120
123
|
exit
|
121
124
|
end
|
125
|
+
|
126
|
+
def version
|
127
|
+
puts "wikian #{VERSION}"
|
128
|
+
exit
|
129
|
+
end
|
122
130
|
end
|
data/lib/wikian/get.rb
CHANGED
@@ -2,6 +2,7 @@ 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
|
5
6
|
|
6
7
|
class Get < Subcommand
|
7
8
|
attr_accessor :title
|
@@ -13,6 +14,8 @@ class Wikian
|
|
13
14
|
|
14
15
|
url = URI(args.find{|arg| arg =~ URI.regexp})
|
15
16
|
|
17
|
+
raise BadUrlError unless url.path
|
18
|
+
|
16
19
|
@title = File.basename(url.path)
|
17
20
|
|
18
21
|
@output_file = title + '.' + url.host
|
@@ -54,7 +57,6 @@ class Wikian
|
|
54
57
|
|
55
58
|
# this is ugly, but Wikipedia is inconsistent in their JSON value for 'pages'. Sometimes it's a hash, sometimes it's an array.
|
56
59
|
if pages.respond_to? :keys
|
57
|
-
byebug
|
58
60
|
create_wiki.call(pages.values.first['title'], pages.values.first['revisions'])
|
59
61
|
else
|
60
62
|
pages.each do |page|
|
@@ -65,7 +67,7 @@ class Wikian
|
|
65
67
|
rescue => e
|
66
68
|
puts "An error occurred while extracting the wikitext",
|
67
69
|
"Try using a new config file by pasing the '-t' option.",
|
68
|
-
"Or pass '-d' option for debugging"
|
70
|
+
"Or pass the '-d' option for debugging"
|
69
71
|
exit
|
70
72
|
end
|
71
73
|
|
@@ -81,9 +83,9 @@ class Wikian
|
|
81
83
|
- revisions
|
82
84
|
rvprop:
|
83
85
|
- content
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
#rvsection: # get specific sections
|
87
|
+
# - 0
|
88
|
+
# - 2
|
87
89
|
rvslots:
|
88
90
|
- main
|
89
91
|
formatversion:
|
data/lib/wikian/post.rb
CHANGED
@@ -107,12 +107,15 @@ class Wikian
|
|
107
107
|
# pass the wikitext in request body
|
108
108
|
@body_text = wikitext
|
109
109
|
end
|
110
|
-
if args.
|
110
|
+
if args.have?(%w(-c --captcha))
|
111
111
|
params['captchaid'], params['captchaword'] = args[args.index('-c')+1].split(':')
|
112
112
|
end
|
113
|
-
if args.
|
113
|
+
if args.have?(%w(-m --message))
|
114
114
|
params['summary'] = args[args.index('-m')+1]
|
115
115
|
end
|
116
|
+
if args.have?(%w(-s --section))
|
117
|
+
params['section'] = args[args.index('-s')+1]
|
118
|
+
end
|
116
119
|
@query = URI.encode_www_form(params)
|
117
120
|
end
|
118
121
|
|
data/lib/wikian/search.rb
CHANGED
data/lib/wikian/subcommand.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
#!/usr/bin/env -S ruby -W0
|
2
2
|
class Wikian
|
3
|
+
class WikianSubcommandError < StandardError; end
|
4
|
+
class MissingConfigFileError < WikianSubcommandError; end
|
5
|
+
|
3
6
|
# class to be inherited by other Wikian classes
|
4
7
|
class Subcommand
|
5
8
|
attr_accessor :args, :res, :yaml, :query, :title, :api_url, :debug, :output_file
|
@@ -15,10 +18,14 @@ class Wikian
|
|
15
18
|
|
16
19
|
@debug = (args & %w(-d --debug)).length > 0 ? true : false
|
17
20
|
|
21
|
+
raise MissingConfigFileError unless File.exist?(Wikian::CONFIG_FILE)
|
18
22
|
@yaml=YAML.load(File.open(Wikian::CONFIG_FILE))
|
19
23
|
|
20
24
|
# some params like 'titles' can contain multiple entries joined by '|'. More info in Wikipedia API docs
|
21
25
|
@params = Hash[yaml['api'].keys.zip(yaml['api'].values.map{|arr| arr.join("|")})]
|
26
|
+
rescue MissingConfigFileError => e
|
27
|
+
puts "#{e.class} try passing the '-t' option to generate #{Wikian::CONFIG_FILE} in #{__FILE__}"
|
28
|
+
exit
|
22
29
|
end
|
23
30
|
|
24
31
|
def make_template
|
data/lib/wikian/version.rb
CHANGED