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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7641f6124dd8e9db31fa2dc7688146107db693d65d8347af57d45ee40205519
4
- data.tar.gz: a9def9f5d7d2cc6a00c375f9e690e96aaf193a601359ae98fb1f4abea1f31402
3
+ metadata.gz: e066880739b70e35ea72420c4692f03b06edb3e166de62e4266c2fb0ed987361
4
+ data.tar.gz: 2844bbad116737e2325e917670bb2e91820ccc8f6d4304cf1f84e826832cc0b5
5
5
  SHA512:
6
- metadata.gz: d7887e82d7f20332717314772cba3ca4bbb4d7cb54d5a1dab3235f1c248654949c3427feaa6915324b437117d0e87147c219a2acbed7654ddeb22c89541abc50
7
- data.tar.gz: 37998e9226c13ddfa504921859e4da1f9f8e96a19edcc617faaf30a7a387d80fff4768e29c868f9ebfb363c168baaada1f3280cbc241c3f91c10c732e378c790
6
+ metadata.gz: '065693de9893b9741bd4b6cc3ee86c66ae7c7d9406acede75cedc78dba156351f0412ce187aed004325ebd7e9c0bdb1bada66ffabf9df158b304ec2f6d178c26'
7
+ data.tar.gz: 50feea8fa794dfe9b53acce2cbd161bd641a6407df241c5c69ebcacfe6a5930ed9be2e68f37911d82455d143526d4ae14ce3da577b374d36b09ab725f8b77dd4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wikian (0.1.5)
4
+ wikian (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- You can then edit the the article in your favorite text editor and uploaded:
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
 
@@ -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
 
@@ -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
- #rvsection:
88
- # - 0
89
- # - 2
86
+ #rvsection: # get specific sections
87
+ # - 0
88
+ # - 2
90
89
  rvslots:
91
90
  - main
92
91
  formatversion:
@@ -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.include?('-c')
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.include?('-m')
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
 
@@ -30,8 +30,8 @@ class Wikian
30
30
  - query
31
31
  list:
32
32
  - search
33
- srsearch:
34
- - Craig Noone
33
+ srsearch: # text to search for. You can use multiple
34
+ - Mr. Fixit
35
35
  format:
36
36
  - json
37
37
  eos
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Wikian
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergioro