wikian 0.1.5 → 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/Gemfile.lock +1 -1
- data/README.md +18 -1
- data/lib/wikian.rb +1 -0
- data/lib/wikian/get.rb +4 -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/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -55,12 +55,29 @@ Writing to Wikipedia:Sandbox.en.wikipedia.org.json
|
|
55
55
|
Writing to Wikipedia:Sandbox.en.wikipedia.org.wiki
|
56
56
|
```
|
57
57
|
|
58
|
-
|
58
|
+
Then edit the the article in your favorite text editor and upload it:
|
59
59
|
|
60
60
|
```bash
|
61
61
|
$ wi post Wikipedia:Sandbox.en.wikipedia.org.wiki
|
62
62
|
Article uploaded
|
63
63
|
```
|
64
64
|
|
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
|
+
|
65
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.
|
66
83
|
|
data/lib/wikian.rb
CHANGED
@@ -83,6 +83,7 @@ class Wikian
|
|
83
83
|
-m, --message MESSAGE add a commit message (HIGHLY recommended)
|
84
84
|
-p, --prepend prepend the input file
|
85
85
|
-r, --remove-cookie remove API cookie
|
86
|
+
-s, --section NUMBER section to edit
|
86
87
|
-t, --template create template configuration file
|
87
88
|
-v, --version
|
88
89
|
|
data/lib/wikian/get.rb
CHANGED
@@ -57,7 +57,6 @@ class Wikian
|
|
57
57
|
|
58
58
|
# this is ugly, but Wikipedia is inconsistent in their JSON value for 'pages'. Sometimes it's a hash, sometimes it's an array.
|
59
59
|
if pages.respond_to? :keys
|
60
|
-
byebug
|
61
60
|
create_wiki.call(pages.values.first['title'], pages.values.first['revisions'])
|
62
61
|
else
|
63
62
|
pages.each do |page|
|
@@ -68,7 +67,7 @@ class Wikian
|
|
68
67
|
rescue => e
|
69
68
|
puts "An error occurred while extracting the wikitext",
|
70
69
|
"Try using a new config file by pasing the '-t' option.",
|
71
|
-
"Or pass '-d' option for debugging"
|
70
|
+
"Or pass the '-d' option for debugging"
|
72
71
|
exit
|
73
72
|
end
|
74
73
|
|
@@ -84,9 +83,9 @@ class Wikian
|
|
84
83
|
- revisions
|
85
84
|
rvprop:
|
86
85
|
- content
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
#rvsection: # get specific sections
|
87
|
+
# - 0
|
88
|
+
# - 2
|
90
89
|
rvslots:
|
91
90
|
- main
|
92
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