sunflower 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +4 -4
- data/README +1 -1
- data/bin/sunflower-setup +68 -68
- data/example-bot.rb +11 -11
- data/lib/sunflower.rb +3 -3
- data/lib/sunflower/core.rb +2 -2
- data/use-easy-bot.rb +53 -53
- metadata +5 -5
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Sunflower is licensed under CC-BY-SA 3.0.
|
2
|
-
|
3
|
-
Author: matma.rex@gmail.com
|
4
|
-
|
1
|
+
Sunflower is licensed under CC-BY-SA 3.0.
|
2
|
+
|
3
|
+
Author: matma.rex@gmail.com
|
4
|
+
|
data/README
CHANGED
data/bin/sunflower-setup
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
require 'sunflower'
|
2
|
-
|
3
|
-
|
4
|
-
path = Sunflower.path
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
puts "Welcome to Sunflower's setup script."
|
9
|
-
puts ""
|
10
|
-
|
11
|
-
puts "If you set your home wiki and userdata, you will not have to enter it in every script."
|
12
|
-
puts "Your userdata will be saved (IN PLAINTEXT!) in this file:"
|
13
|
-
puts " #{path}"
|
14
|
-
|
15
|
-
puts ""
|
16
|
-
|
17
|
-
print "Enter your home wiki (for ex. en.wikipedia.org): "
|
18
|
-
home=gets.strip
|
19
|
-
|
20
|
-
print "Enter your bot's nick on the home wiki: "
|
21
|
-
nick=gets.strip
|
22
|
-
|
23
|
-
print "Enter your bot's password on home wiki (WILL BE SHOWN IN PLAINTEXT): "
|
24
|
-
pass=gets.strip
|
25
|
-
|
26
|
-
puts ""
|
27
|
-
|
28
|
-
worked = true
|
29
|
-
puts "Trying to connect with the data provided..."
|
30
|
-
begin
|
31
|
-
s=Sunflower.new home
|
32
|
-
s.login nick, pass
|
33
|
-
rescue
|
34
|
-
worked = false
|
35
|
-
error = $!.message
|
36
|
-
end
|
37
|
-
|
38
|
-
if worked
|
39
|
-
puts "It seems to work!"
|
40
|
-
puts "WARNING! USER DOES NOT HAVE BOT RIGHTS!" if !s.isBot?
|
41
|
-
else
|
42
|
-
puts "Whoops, it didn't work. The error message is:"
|
43
|
-
puts error
|
44
|
-
end
|
45
|
-
|
46
|
-
save = worked
|
47
|
-
|
48
|
-
if !worked
|
49
|
-
begin
|
50
|
-
print "Do you want to save the data anyway? [yn] "
|
51
|
-
ans = gets.strip
|
52
|
-
end until ans=~/[yn]/i
|
53
|
-
|
54
|
-
save = (ans.downcase=='y')
|
55
|
-
end
|
56
|
-
|
57
|
-
if save
|
58
|
-
f=File.open(path, "w")
|
59
|
-
f.write [home, nick, pass].join "\n"
|
60
|
-
f.close
|
61
|
-
|
62
|
-
puts "User data has been saved. Remember that your password is saved in plaintext!"
|
63
|
-
puts ""
|
64
|
-
|
65
|
-
puts "If you ever want to erase your login data, simply delete the file."
|
66
|
-
else
|
67
|
-
puts "User data has not been saved. You can run this setup again anytime."
|
68
|
-
end
|
1
|
+
require 'sunflower'
|
2
|
+
|
3
|
+
|
4
|
+
path = Sunflower.path
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
puts "Welcome to Sunflower's setup script."
|
9
|
+
puts ""
|
10
|
+
|
11
|
+
puts "If you set your home wiki and userdata, you will not have to enter it in every script."
|
12
|
+
puts "Your userdata will be saved (IN PLAINTEXT!) in this file:"
|
13
|
+
puts " #{path}"
|
14
|
+
|
15
|
+
puts ""
|
16
|
+
|
17
|
+
print "Enter your home wiki (for ex. en.wikipedia.org): "
|
18
|
+
home=gets.strip
|
19
|
+
|
20
|
+
print "Enter your bot's nick on the home wiki: "
|
21
|
+
nick=gets.strip
|
22
|
+
|
23
|
+
print "Enter your bot's password on home wiki (WILL BE SHOWN IN PLAINTEXT): "
|
24
|
+
pass=gets.strip
|
25
|
+
|
26
|
+
puts ""
|
27
|
+
|
28
|
+
worked = true
|
29
|
+
puts "Trying to connect with the data provided..."
|
30
|
+
begin
|
31
|
+
s=Sunflower.new home
|
32
|
+
s.login nick, pass
|
33
|
+
rescue
|
34
|
+
worked = false
|
35
|
+
error = $!.message
|
36
|
+
end
|
37
|
+
|
38
|
+
if worked
|
39
|
+
puts "It seems to work!"
|
40
|
+
puts "WARNING! USER DOES NOT HAVE BOT RIGHTS!" if !s.isBot?
|
41
|
+
else
|
42
|
+
puts "Whoops, it didn't work. The error message is:"
|
43
|
+
puts error
|
44
|
+
end
|
45
|
+
|
46
|
+
save = worked
|
47
|
+
|
48
|
+
if !worked
|
49
|
+
begin
|
50
|
+
print "Do you want to save the data anyway? [yn] "
|
51
|
+
ans = gets.strip
|
52
|
+
end until ans=~/[yn]/i
|
53
|
+
|
54
|
+
save = (ans.downcase=='y')
|
55
|
+
end
|
56
|
+
|
57
|
+
if save
|
58
|
+
f=File.open(path, "w")
|
59
|
+
f.write [home, nick, pass].join "\n"
|
60
|
+
f.close
|
61
|
+
|
62
|
+
puts "User data has been saved. Remember that your password is saved in plaintext!"
|
63
|
+
puts ""
|
64
|
+
|
65
|
+
puts "If you ever want to erase your login data, simply delete the file."
|
66
|
+
else
|
67
|
+
puts "User data has not been saved. You can run this setup again anytime."
|
68
|
+
end
|
data/example-bot.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# This is the most basic bot possible.
|
2
|
-
|
3
|
-
require 'sunflower-commontasks.rb'
|
4
|
-
|
5
|
-
s=Sunflower.new
|
6
|
-
s.login
|
7
|
-
|
8
|
-
$summary='Sunflower: test'
|
9
|
-
|
10
|
-
p=Page.get('Test')
|
11
|
-
p.write p.text+"\n\ntest"
|
1
|
+
# This is the most basic bot possible.
|
2
|
+
|
3
|
+
require 'sunflower-commontasks.rb'
|
4
|
+
|
5
|
+
s=Sunflower.new
|
6
|
+
s.login
|
7
|
+
|
8
|
+
$summary='Sunflower: test'
|
9
|
+
|
10
|
+
p=Page.get('Test')
|
11
|
+
p.write p.text+"\n\ntest"
|
12
12
|
p.save
|
data/lib/sunflower.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'sunflower/core'
|
3
|
-
require 'sunflower/commontasks'
|
1
|
+
# coding: utf-8
|
2
|
+
require 'sunflower/core'
|
3
|
+
require 'sunflower/commontasks'
|
4
4
|
require 'sunflower/listmaker'
|
data/lib/sunflower/core.rb
CHANGED
@@ -19,7 +19,7 @@ class SunflowerError < StandardError; end
|
|
19
19
|
#
|
20
20
|
# You can use multiple Sunflowers at once, to work on multiple wikis.
|
21
21
|
class Sunflower
|
22
|
-
VERSION = '0.4'
|
22
|
+
VERSION = '0.4.1'
|
23
23
|
|
24
24
|
INVALID_CHARS = %w(# < > [ ] | { })
|
25
25
|
INVALID_CHARS_REGEX = Regexp.union *INVALID_CHARS
|
@@ -214,7 +214,7 @@ class Page
|
|
214
214
|
@text = r['revisions'][0]['*']
|
215
215
|
end
|
216
216
|
|
217
|
-
@orig_text = @text
|
217
|
+
@orig_text = @text.dup
|
218
218
|
|
219
219
|
@preloaded_text = true
|
220
220
|
end
|
data/use-easy-bot.rb
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
require 'sunflower-commontasks.rb'
|
2
|
-
|
3
|
-
# EDIT WIKI URL BELOW
|
4
|
-
s=Sunflower.new('en.wikipedia.org')
|
5
|
-
|
6
|
-
print "Logging in to #{s.wikiURL}... "
|
7
|
-
# EDIT USERNAME AND PASSWORD BELOW
|
8
|
-
s.login('Username','password')
|
9
|
-
print "done!\n"
|
10
|
-
|
11
|
-
print "Reading articles list... "
|
12
|
-
# EDIT FILENAME BELOW
|
13
|
-
f=File.open('filename.txt')
|
14
|
-
list=f.read.sub(/\357\273\277/,'').strip.split(/\r?\n/)
|
15
|
-
print "done!\n\n"
|
16
|
-
|
17
|
-
# EDIT SUMMARY BELOW
|
18
|
-
$summary='Sunflower: test'
|
19
|
-
|
20
|
-
list.each do |title|
|
21
|
-
print "Reading page #{title}... "
|
22
|
-
page=Page.get(title)
|
23
|
-
print "done.\n"
|
24
|
-
print "Modifying... "
|
25
|
-
|
26
|
-
page.execute([
|
27
|
-
# commands to execute on each article
|
28
|
-
# zostaną wykonane w takiej kolejności, jak podane; wywal albo zakomentuj i wstaw własne
|
29
|
-
# EDIT BELOW
|
30
|
-
[:replace, 'test1', 'test2', true], #zamieni pierwsze wystąpienie test1 na test2 w artykule
|
31
|
-
[:replace, 'asd', 'fgh'], #jw., ale zamieni każde wystąpienie
|
32
|
-
[:replace, /(\d+).(\d+)/, '\1,\2'], #jw., ale używając regeksów; należy używać \1, nie $1
|
33
|
-
[:prepend, 'Some text.'], #doda na początku artykułu dwa entery i tekst
|
34
|
-
[:append, 'Some more text.', 4], #jw., ale na końcu i 4 entery; można podać dowolną liczbę
|
35
|
-
[:code_cleanup], #część WP:SK, zamierzam uzupełnić
|
36
|
-
[:friendly_infobox], #oczyszczony sprzątacz infoboksów
|
37
|
-
|
38
|
-
#a teraz przykłady flag; też je wywal/zakomentuj
|
39
|
-
#każda flaga ma skróty; required=r, summary=s - można używać zamiennie
|
40
|
-
[[:replace, 'required'], 'qwe', 'rty'] #zamieni każde qwe na rty; jeśli nie uda mu się wykonać żadnych zmian, anuluje wszystko, co zrobiły inne polecenia oraz nie będzie zapisywał artykułu
|
41
|
-
[:replace, 'r', 'summary:testowy opis'], 'qwe', 'rty'] #jw., ale w razie sukcesu doda tekst (wraz z przecinkiem) do opisu zmian; można używać dowolnej liczby flag dla jednego polecenia, w dowolnej kolejności
|
42
|
-
|
43
|
-
#Teoretycznie możliwe jest też użycie flag only-if oraz only-if-not (skróty: oi, !oi; po dwukropku trzeba podać nazwę modułu (np. replace), który musi/nie może zostać uruchomiony i wykonać zmian, aby uruchomił się moduł oznaczony flagą. Ale to trochę bez sensu, bo w gruncie rzeczy nie wiadomo, co taki replace zrobił, a na razie wszystkie pozostałe zawsze coś zmienią. Kiedyś jednak może się przydać).
|
44
|
-
# EDIT ABOVE
|
45
|
-
])
|
46
|
-
|
47
|
-
print "done.\n"
|
48
|
-
print "Saving... "
|
49
|
-
page.save
|
50
|
-
print "done!\n\n"
|
51
|
-
end
|
52
|
-
|
53
|
-
print 'Finished! Press any key to close.'
|
1
|
+
require 'sunflower-commontasks.rb'
|
2
|
+
|
3
|
+
# EDIT WIKI URL BELOW
|
4
|
+
s=Sunflower.new('en.wikipedia.org')
|
5
|
+
|
6
|
+
print "Logging in to #{s.wikiURL}... "
|
7
|
+
# EDIT USERNAME AND PASSWORD BELOW
|
8
|
+
s.login('Username','password')
|
9
|
+
print "done!\n"
|
10
|
+
|
11
|
+
print "Reading articles list... "
|
12
|
+
# EDIT FILENAME BELOW
|
13
|
+
f=File.open('filename.txt')
|
14
|
+
list=f.read.sub(/\357\273\277/,'').strip.split(/\r?\n/)
|
15
|
+
print "done!\n\n"
|
16
|
+
|
17
|
+
# EDIT SUMMARY BELOW
|
18
|
+
$summary='Sunflower: test'
|
19
|
+
|
20
|
+
list.each do |title|
|
21
|
+
print "Reading page #{title}... "
|
22
|
+
page=Page.get(title)
|
23
|
+
print "done.\n"
|
24
|
+
print "Modifying... "
|
25
|
+
|
26
|
+
page.execute([
|
27
|
+
# commands to execute on each article
|
28
|
+
# zostaną wykonane w takiej kolejności, jak podane; wywal albo zakomentuj i wstaw własne
|
29
|
+
# EDIT BELOW
|
30
|
+
[:replace, 'test1', 'test2', true], #zamieni pierwsze wystąpienie test1 na test2 w artykule
|
31
|
+
[:replace, 'asd', 'fgh'], #jw., ale zamieni każde wystąpienie
|
32
|
+
[:replace, /(\d+).(\d+)/, '\1,\2'], #jw., ale używając regeksów; należy używać \1, nie $1
|
33
|
+
[:prepend, 'Some text.'], #doda na początku artykułu dwa entery i tekst
|
34
|
+
[:append, 'Some more text.', 4], #jw., ale na końcu i 4 entery; można podać dowolną liczbę
|
35
|
+
[:code_cleanup], #część WP:SK, zamierzam uzupełnić
|
36
|
+
[:friendly_infobox], #oczyszczony sprzątacz infoboksów
|
37
|
+
|
38
|
+
#a teraz przykłady flag; też je wywal/zakomentuj
|
39
|
+
#każda flaga ma skróty; required=r, summary=s - można używać zamiennie
|
40
|
+
[[:replace, 'required'], 'qwe', 'rty'] #zamieni każde qwe na rty; jeśli nie uda mu się wykonać żadnych zmian, anuluje wszystko, co zrobiły inne polecenia oraz nie będzie zapisywał artykułu
|
41
|
+
[:replace, 'r', 'summary:testowy opis'], 'qwe', 'rty'] #jw., ale w razie sukcesu doda tekst (wraz z przecinkiem) do opisu zmian; można używać dowolnej liczby flag dla jednego polecenia, w dowolnej kolejności
|
42
|
+
|
43
|
+
#Teoretycznie możliwe jest też użycie flag only-if oraz only-if-not (skróty: oi, !oi; po dwukropku trzeba podać nazwę modułu (np. replace), który musi/nie może zostać uruchomiony i wykonać zmian, aby uruchomił się moduł oznaczony flagą. Ale to trochę bez sensu, bo w gruncie rzeczy nie wiadomo, co taki replace zrobił, a na razie wszystkie pozostałe zawsze coś zmienią. Kiedyś jednak może się przydać).
|
44
|
+
# EDIT ABOVE
|
45
|
+
])
|
46
|
+
|
47
|
+
print "done.\n"
|
48
|
+
print "Saving... "
|
49
|
+
page.save
|
50
|
+
print "done!\n\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
print 'Finished! Press any key to close.'
|
54
54
|
gets
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunflower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &8696472 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8696472
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &8695752 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8695752
|
36
36
|
description: Sunflower is a lightweight library to provide access to MediaWiki API
|
37
37
|
from Ruby.
|
38
38
|
email: matma.rex@gmail.com
|