reddit_bot 0.1.3 → 1.0.0
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/examples/boilerplate.rb +8 -2
- data/lib/reddit_bot.rb +31 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 305bb60aab77793751a1ebd2a999dfc657cb7dfe
|
4
|
+
data.tar.gz: 6ca3d8ebf4d31cb980ab6694034a7b2d85197cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a02edccecbdb082ac0ef432d4402564931f47ff08c1c472e8370660f492e5fefab1c4eead7c5c3ff758342adaf738d6b394a50a231fa83e07eb3bbb12d0f3ec
|
7
|
+
data.tar.gz: 0fd8bbb254327df02bc65b0c2cf77cbefd4280b66542a8c4f35771ab273c0ae657b41ffe811732fb22f6d198eeb2be8c6afec40dcc049c6f1a438fa95929fb0a
|
data/examples/boilerplate.rb
CHANGED
@@ -7,9 +7,15 @@ require_relative File.join "../..",
|
|
7
7
|
"download_with_retry"
|
8
8
|
|
9
9
|
require "reddit_bot"
|
10
|
-
|
11
|
-
RedditBot
|
10
|
+
|
11
|
+
if RedditBot::VERSION <= "0.1.3"
|
12
|
+
|
13
|
+
RedditBot.init *File.read("secrets").split, ignore_captcha: true
|
14
|
+
|
15
|
+
end
|
12
16
|
|
13
17
|
require_relative File.join "../..",
|
14
18
|
*(".." if ENV["LOGNAME"] == "nakilon"),
|
15
19
|
"awsstatus/2.rb"
|
20
|
+
|
21
|
+
require "yaml"
|
data/lib/reddit_bot.rb
CHANGED
@@ -8,24 +8,24 @@ require "json"
|
|
8
8
|
|
9
9
|
|
10
10
|
module RedditBot
|
11
|
-
VERSION = "0.
|
11
|
+
VERSION = "1.0.0"
|
12
12
|
|
13
|
-
class
|
13
|
+
class Bot
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
attr_accessor :iden_and_captcha
|
18
|
-
attr_accessor :ignore_captcha
|
19
|
-
attr_accessor :secrets
|
20
|
-
|
21
|
-
def init *secrets, **kwargs
|
22
|
-
@secrets = secrets
|
23
|
-
kwargs
|
15
|
+
def initialize secrets, **kwargs
|
16
|
+
@secrets = secrets.values_at *%i{ client_id client_secret password login }
|
24
17
|
@ignore_captcha = kwargs[:ignore_captcha]
|
25
18
|
end
|
26
19
|
|
27
|
-
|
28
|
-
|
20
|
+
# attr_accessor :token_cached
|
21
|
+
# attr_accessor :username
|
22
|
+
# attr_accessor :iden_and_captcha
|
23
|
+
# attr_accessor :ignore_captcha
|
24
|
+
# attr_accessor :secrets
|
25
|
+
|
26
|
+
def json mtd, url, _form = []
|
27
|
+
form = Hash[_form]
|
28
|
+
response = JSON.parse resp_with_token mtd, url, form.merge({api_type: "json"})
|
29
29
|
if response.is_a?(Hash) && response["json"] # for example, flairlist.json and {"error": 403} do not have it
|
30
30
|
puts "ERROR OCCURED on #{[mtd, url]}" unless response["json"]["errors"].empty?
|
31
31
|
# pp response["json"]
|
@@ -34,10 +34,10 @@ module RedditBot
|
|
34
34
|
case error
|
35
35
|
when "ALREADY_SUB" ; puts "was rejected by moderator if you didn't see in dups"
|
36
36
|
when "BAD_CAPTCHA" ; update_captcha
|
37
|
-
json mtd, url, form.
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
json mtd, url, form.merger( {
|
38
|
+
iden: @iden_and_captcha[0],
|
39
|
+
captcha: @iden_and_captcha[1],
|
40
|
+
} ) unless @ignore_captcha
|
41
41
|
else ; raise error
|
42
42
|
end
|
43
43
|
end
|
@@ -48,10 +48,8 @@ module RedditBot
|
|
48
48
|
def wiki_edit subreddit, page, text
|
49
49
|
json :post,
|
50
50
|
"/r/#{subreddit}/api/wiki/edit",
|
51
|
-
|
52
|
-
|
53
|
-
["content", text]
|
54
|
-
]
|
51
|
+
page: page,
|
52
|
+
content: text
|
55
53
|
# ["previous", result["data"]["children"].last["id"]],
|
56
54
|
end
|
57
55
|
|
@@ -60,13 +58,11 @@ module RedditBot
|
|
60
58
|
def token
|
61
59
|
return @token_cached if @token_cached
|
62
60
|
response = JSON.parse(reddit_resp(:post,
|
63
|
-
"https://www.reddit.com/api/v1/access_token",
|
64
|
-
|
65
|
-
[
|
66
|
-
|
67
|
-
|
68
|
-
],
|
69
|
-
{}, # headers
|
61
|
+
"https://www.reddit.com/api/v1/access_token", {
|
62
|
+
grant_type: "password",
|
63
|
+
username: @username = @secrets[3],
|
64
|
+
password: @secrets[2],
|
65
|
+
}, {}, # headers
|
70
66
|
[@secrets[0], @secrets[1]],
|
71
67
|
))
|
72
68
|
raise response.inspect unless @token_cached = response["access_token"]
|
@@ -181,13 +177,13 @@ module RedditBot
|
|
181
177
|
fail response.to_hash["x-ratelimit-remaining"][0] \
|
182
178
|
if response.to_hash["x-ratelimit-remaining"] &&
|
183
179
|
response.to_hash["x-ratelimit-remaining"][0].size <= 2
|
184
|
-
|
185
|
-
#
|
186
|
-
#
|
187
|
-
# puts request.
|
188
|
-
#
|
189
|
-
#
|
190
|
-
|
180
|
+
|
181
|
+
# if response.code == "401"
|
182
|
+
# puts request.path
|
183
|
+
# puts request.body
|
184
|
+
# pp request.to_hash
|
185
|
+
# end
|
186
|
+
|
191
187
|
response
|
192
188
|
end
|
193
189
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|