reddit_bot 1.7.7 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reddit_bot.rb +36 -21
- data/reddit_bot.gemspec +9 -11
- metadata +12 -80
- data/.gitignore +0 -5
- data/Gemfile +0 -5
- data/README.md +0 -101
- data/Rakefile +0 -6
- data/examples/.bashrc +0 -2
- data/examples/.gitignore +0 -2
- data/examples/Gemfile.lock +0 -17
- data/examples/boilerplate.rb +0 -12
- data/examples/councilofricks/Gemfile +0 -4
- data/examples/councilofricks/Gemfile.lock +0 -17
- data/examples/councilofricks/main.rb +0 -58
- data/examples/cptflairbot3/.bashrc +0 -1
- data/examples/cptflairbot3/Code.gs +0 -13
- data/examples/cptflairbot3/Gemfile +0 -5
- data/examples/cptflairbot3/Gemfile.lock +0 -74
- data/examples/cptflairbot3/app.js +0 -40
- data/examples/cptflairbot3/casual/casualpokemontrades.htm +0 -910
- data/examples/cptflairbot3/casual/script.js +0 -55
- data/examples/cptflairbot3/casual/style.css +0 -1099
- data/examples/cptflairbot3/log.htm +0 -1
- data/examples/cptflairbot3/main.rb +0 -62
- data/examples/cptflairbot3/package.json +0 -6
- data/examples/cptflairbot3/pubsub.rb +0 -30
- data/examples/cptflairbot3/update_gas_hook_secret.rb +0 -4
- data/examples/devflairbot/Gemfile +0 -6
- data/examples/devflairbot/Gemfile.lock +0 -74
- data/examples/devflairbot/main.rb +0 -81
- data/examples/dut/Gemfile +0 -4
- data/examples/dut/Gemfile.lock +0 -24
- data/examples/dut/main.rb +0 -41
- data/examples/get_dimensions.rb +0 -212
- data/examples/iostroubleshooting/Gemfile +0 -5
- data/examples/iostroubleshooting/Gemfile.lock +0 -16
- data/examples/iostroubleshooting/main.rb +0 -36
- data/examples/johnnymarr/Gemfile +0 -3
- data/examples/johnnymarr/Gemfile.lock +0 -17
- data/examples/johnnymarr/main.rb +0 -54
- data/examples/johnnymarr/twitter.rb +0 -80
- data/examples/largeimages/Gemfile +0 -11
- data/examples/largeimages/Gemfile.lock +0 -105
- data/examples/largeimages/main.rb +0 -173
- data/examples/largeimagesreview/Gemfile +0 -4
- data/examples/largeimagesreview/Gemfile.lock +0 -15
- data/examples/largeimagesreview/main.rb +0 -43
- data/examples/mlgtv/Gemfile +0 -4
- data/examples/mlgtv/Gemfile.lock +0 -23
- data/examples/mlgtv/channels.txt +0 -127
- data/examples/mlgtv/main.rb +0 -160
- data/examples/net_http_utils.rb +0 -148
- data/examples/oneplus/Gemfile +0 -5
- data/examples/oneplus/Gemfile.lock +0 -26
- data/examples/oneplus/main.rb +0 -43
- data/examples/realtimeww2/.bashrc +0 -1
- data/examples/realtimeww2/Gemfile +0 -3
- data/examples/realtimeww2/Gemfile.lock +0 -17
- data/examples/realtimeww2/main.rb +0 -129
- data/examples/sexypizza/Gemfile +0 -3
- data/examples/sexypizza/Gemfile.lock +0 -15
- data/examples/sexypizza/main.rb +0 -33
- data/examples/unisa/Gemfile +0 -4
- data/examples/unisa/Gemfile.lock +0 -24
- data/examples/unisa/main.rb +0 -41
- data/examples/wallpaper/Gemfile +0 -5
- data/examples/wallpaper/Gemfile.lock +0 -34
- data/examples/wallpaper/main.rb +0 -27
- data/examples/yayornay/Gemfile +0 -3
- data/examples/yayornay/Gemfile.lock +0 -15
- data/examples/yayornay/main.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a4b6056d152bae03ffd563ae1a4fd1074871cd9
|
4
|
+
data.tar.gz: ae3eeee686686d80659b91d702f752617333c065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 732462c5e167fdab3520dd669687e0871a67ff781613befe9e4ea5122e2b383f44a2fa8ce9fdbb14ea208c26e407b901b070851a033019ac285ba91a32504c7c
|
7
|
+
data.tar.gz: 865ef62f2c73a4de9fddc5ea4af0ba8ab9c03856bb1e6d093e5f7ca8767bf67dbae37b3c78fae3eeead39b7fd1824199fba8e33ae8eaf8aec0211a7f4e80af59
|
data/lib/reddit_bot.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
STDOUT.sync = true
|
2
|
-
# require "pp"
|
3
2
|
|
4
3
|
require "openssl"
|
5
4
|
require "json"
|
@@ -15,12 +14,8 @@ module RedditBot
|
|
15
14
|
self.logger = Logger.new STDOUT
|
16
15
|
|
17
16
|
class Bot
|
18
|
-
|
19
|
-
# bot's Reddit username; set via constructor parameter secrets[:login]
|
20
17
|
attr_reader :name
|
21
18
|
|
22
|
-
# [secrets] +Hash+ with keys :client_id, :client_secret, :password: and :login
|
23
|
-
# [kwargs] keyword params may include :subreddit for clever methods
|
24
19
|
def initialize secrets, **kwargs
|
25
20
|
@name, @secret_password, @user_agent, *@secret_auth = secrets.values_at *%i{ login password user_agent client_id client_secret }
|
26
21
|
# @ignore_captcha = true
|
@@ -28,12 +23,14 @@ module RedditBot
|
|
28
23
|
@subreddit = kwargs[:subreddit]
|
29
24
|
end
|
30
25
|
|
31
|
-
# [mtd] +Symbol+ :get or :post
|
32
|
-
# [path] +String+ an API method
|
33
|
-
# [_form] +Array+ or +Hash+ API method params
|
34
26
|
def json mtd, path, _form = []
|
35
27
|
form = Hash[_form]
|
36
|
-
response =
|
28
|
+
response = begin
|
29
|
+
JSON.load resp_with_token mtd, path, form.merge({api_type: "json"})
|
30
|
+
rescue JSON::ParserError
|
31
|
+
$!.message.slice! 1000..-1
|
32
|
+
raise
|
33
|
+
end
|
37
34
|
if response.is_a?(Hash) && response["json"] && # for example, flairlist.json and {"error": 403} do not have it
|
38
35
|
!response["json"]["errors"].empty?
|
39
36
|
Module.nesting[1].logger.error "ERROR OCCURED on #{[mtd, path]}"
|
@@ -70,8 +67,6 @@ module RedditBot
|
|
70
67
|
# # ["previous", result["data"]["children"].last["id"]],
|
71
68
|
# end
|
72
69
|
|
73
|
-
# [reason] :nodoc:
|
74
|
-
# [thing_id] +String+ fullname of a "link, commenr or message"
|
75
70
|
def report reason, thing_id
|
76
71
|
Module.nesting[1].logger.warn "reporting '#{thing_id}'"
|
77
72
|
json :post, "/api/report",
|
@@ -80,9 +75,6 @@ module RedditBot
|
|
80
75
|
thing_id: thing_id
|
81
76
|
end
|
82
77
|
|
83
|
-
# [post] JSON object of a post of self.post
|
84
|
-
# [link_flair_css_class] :nodoc:
|
85
|
-
# [link_flair_text] :nodoc:
|
86
78
|
def set_post_flair post, link_flair_css_class, link_flair_text
|
87
79
|
Module.nesting[1].logger.warn "setting flair '#{link_flair_css_class}' with text '#{link_flair_text}' to post '#{post["name"]}'"
|
88
80
|
if {"error"=>403} == @flairselector_choices ||= json(:post, "/r/#{@subreddit}/api/flairselector", link: post["name"])
|
@@ -97,8 +89,6 @@ module RedditBot
|
|
97
89
|
}["flair_template_id"]
|
98
90
|
end
|
99
91
|
|
100
|
-
# [thing_id] +String+ fullname of a post (or self.post?), comment (and private message?)
|
101
|
-
# [text] :nodoc:
|
102
92
|
def leave_a_comment thing_id, text
|
103
93
|
Module.nesting[1].logger.warn "leaving a comment on '#{thing_id}'"
|
104
94
|
json(:post, "/api/comment",
|
@@ -148,11 +138,16 @@ module RedditBot
|
|
148
138
|
result = cache.call(args){ json *args }
|
149
139
|
fail if result.keys != %w{ kind data }
|
150
140
|
fail if result["kind"] != "Listing"
|
151
|
-
fail result["data"].keys.inspect unless
|
152
|
-
|
141
|
+
fail result["data"].keys.inspect unless [
|
142
|
+
%w{ after dist modhash whitelist_status children before },
|
143
|
+
%w{ modhash dist children after before },
|
144
|
+
%w{ after dist modhash geo_filter children before },
|
145
|
+
].include? result["data"].keys
|
153
146
|
@@skip_erroneous_descending_ids[ result["data"]["children"].map do |post|
|
154
147
|
fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
|
155
|
-
post["data"]
|
148
|
+
post["data"].dup.tap do |data|
|
149
|
+
data["url"] = "https://www.reddit.com" + data["url"] if /\A\/r\/[0-9a-zA-Z_]+\/comments\/[0-9a-z]{5,6}\// =~ data["url"] if data["crosspost_parent"]
|
150
|
+
end
|
156
151
|
end ].each do |data|
|
157
152
|
e << data
|
158
153
|
end
|
@@ -162,7 +157,6 @@ module RedditBot
|
|
162
157
|
end
|
163
158
|
end
|
164
159
|
|
165
|
-
# :yields: JSON objects: ["data"] part of post or self.post, top level comment (["children"] element)
|
166
160
|
def each_new_post_with_top_level_comments
|
167
161
|
# TODO add keys assertion like in method above?
|
168
162
|
json(:get, "/r/#{@subreddit}/new")["data"]["children"].each do |post|
|
@@ -176,7 +170,6 @@ module RedditBot
|
|
176
170
|
end
|
177
171
|
end
|
178
172
|
|
179
|
-
# [article] +String+ ID36 of a post or self.post
|
180
173
|
def each_comment_of_the_post_thread article
|
181
174
|
Enumerator.new do |e|
|
182
175
|
f = lambda do |smth|
|
@@ -192,6 +185,27 @@ module RedditBot
|
|
192
185
|
end
|
193
186
|
end
|
194
187
|
|
188
|
+
def subreddit_iterate what, **kwargs
|
189
|
+
Enumerator.new do |e|
|
190
|
+
after = {}
|
191
|
+
loop do
|
192
|
+
break unless marker = json(:get, "/r/#{@subreddit}/#{what}", {limit: 100}.merge(after).merge(kwargs)).tap do |result|
|
193
|
+
fail if %w{ kind data } != result.keys
|
194
|
+
fail if "Listing" != result["kind"]
|
195
|
+
fail result["data"].keys.inspect unless result["data"].keys == %w{ after dist modhash whitelist_status children before } ||
|
196
|
+
result["data"].keys == %w{ modhash dist children after before }
|
197
|
+
result["data"]["children"].each do |post|
|
198
|
+
fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
|
199
|
+
e << ( post["data"].tap do |data|
|
200
|
+
data["url"] = "https://www.reddit.com" + data["url"] if /\A\/r\/[0-9a-zA-Z_]+\/comments\/[0-9a-z]{5,6}\// =~ data["url"] if data["crosspost_parent"]
|
201
|
+
end )
|
202
|
+
end
|
203
|
+
end["data"]["after"]
|
204
|
+
after = {after: marker}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
195
209
|
private
|
196
210
|
|
197
211
|
def token
|
@@ -271,6 +285,7 @@ module RedditBot
|
|
271
285
|
|
272
286
|
require "cgi"
|
273
287
|
def self.tweet2titleNtext tweet
|
288
|
+
pp tweet if ENV["TEST"]
|
274
289
|
text = ""
|
275
290
|
contains_media = false
|
276
291
|
up = ->s{ s.split.map{ |w| "^#{w}" }.join " " }
|
data/reddit_bot.gemspec
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "reddit_bot"
|
3
|
-
spec.version = "1.
|
4
|
-
spec.
|
5
|
-
spec.email = ["nakilon@gmail.com"]
|
3
|
+
spec.version = "1.10.0"
|
4
|
+
spec.summary = "Simple library for Reddit bots"
|
6
5
|
|
7
|
-
spec.
|
8
|
-
spec.
|
9
|
-
spec.homepage = "https://github.com/Nakilon/reddit_bot"
|
6
|
+
spec.author = "Victor Maslov aka Nakilon"
|
7
|
+
spec.email = "nakilon@gmail.com"
|
10
8
|
spec.license = "MIT"
|
9
|
+
spec.metadata = {"source_code_uri" => "https://github.com/Nakilon/reddit_bot"}
|
11
10
|
|
12
|
-
spec.
|
13
|
-
|
14
|
-
|
15
|
-
spec.add_runtime_dependency "json"
|
16
|
-
spec.add_runtime_dependency "nethttputils", "~>0.4.1.0"
|
11
|
+
spec.add_dependency "json_pure"
|
12
|
+
spec.add_dependency "nethttputils", "~>0.4.2.0"
|
17
13
|
# spec.add_development_dependency "bundler", "~> 1.11"
|
18
14
|
# spec.add_development_dependency "rake", "~> 10.0"
|
19
15
|
# spec.add_development_dependency "rspec", "~> 3.0"
|
20
16
|
spec.required_ruby_version = ">= 2.0.0"
|
17
|
+
|
18
|
+
spec.files = %w{ LICENSE.txt reddit_bot.gemspec lib/reddit_bot.rb }
|
21
19
|
end
|
22
20
|
|
23
21
|
# spec.test_files = ["spec/"]
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Victor Maslov
|
7
|
+
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: json_pure
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -30,96 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.4.
|
33
|
+
version: 0.4.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.4.
|
41
|
-
description:
|
42
|
-
email:
|
43
|
-
- nakilon@gmail.com
|
40
|
+
version: 0.4.2.0
|
41
|
+
description:
|
42
|
+
email: nakilon@gmail.com
|
44
43
|
executables: []
|
45
44
|
extensions: []
|
46
45
|
extra_rdoc_files: []
|
47
46
|
files:
|
48
|
-
- ".gitignore"
|
49
|
-
- Gemfile
|
50
47
|
- LICENSE.txt
|
51
|
-
- README.md
|
52
|
-
- Rakefile
|
53
|
-
- examples/.bashrc
|
54
|
-
- examples/.gitignore
|
55
|
-
- examples/Gemfile.lock
|
56
|
-
- examples/boilerplate.rb
|
57
|
-
- examples/councilofricks/Gemfile
|
58
|
-
- examples/councilofricks/Gemfile.lock
|
59
|
-
- examples/councilofricks/main.rb
|
60
|
-
- examples/cptflairbot3/.bashrc
|
61
|
-
- examples/cptflairbot3/Code.gs
|
62
|
-
- examples/cptflairbot3/Gemfile
|
63
|
-
- examples/cptflairbot3/Gemfile.lock
|
64
|
-
- examples/cptflairbot3/app.js
|
65
|
-
- examples/cptflairbot3/casual/casualpokemontrades.htm
|
66
|
-
- examples/cptflairbot3/casual/script.js
|
67
|
-
- examples/cptflairbot3/casual/style.css
|
68
|
-
- examples/cptflairbot3/log.htm
|
69
|
-
- examples/cptflairbot3/main.rb
|
70
|
-
- examples/cptflairbot3/package.json
|
71
|
-
- examples/cptflairbot3/pubsub.rb
|
72
|
-
- examples/cptflairbot3/update_gas_hook_secret.rb
|
73
|
-
- examples/devflairbot/Gemfile
|
74
|
-
- examples/devflairbot/Gemfile.lock
|
75
|
-
- examples/devflairbot/main.rb
|
76
|
-
- examples/dut/Gemfile
|
77
|
-
- examples/dut/Gemfile.lock
|
78
|
-
- examples/dut/main.rb
|
79
|
-
- examples/get_dimensions.rb
|
80
|
-
- examples/iostroubleshooting/Gemfile
|
81
|
-
- examples/iostroubleshooting/Gemfile.lock
|
82
|
-
- examples/iostroubleshooting/main.rb
|
83
|
-
- examples/johnnymarr/Gemfile
|
84
|
-
- examples/johnnymarr/Gemfile.lock
|
85
|
-
- examples/johnnymarr/main.rb
|
86
|
-
- examples/johnnymarr/twitter.rb
|
87
|
-
- examples/largeimages/Gemfile
|
88
|
-
- examples/largeimages/Gemfile.lock
|
89
|
-
- examples/largeimages/main.rb
|
90
|
-
- examples/largeimagesreview/Gemfile
|
91
|
-
- examples/largeimagesreview/Gemfile.lock
|
92
|
-
- examples/largeimagesreview/main.rb
|
93
|
-
- examples/mlgtv/Gemfile
|
94
|
-
- examples/mlgtv/Gemfile.lock
|
95
|
-
- examples/mlgtv/channels.txt
|
96
|
-
- examples/mlgtv/main.rb
|
97
|
-
- examples/net_http_utils.rb
|
98
|
-
- examples/oneplus/Gemfile
|
99
|
-
- examples/oneplus/Gemfile.lock
|
100
|
-
- examples/oneplus/main.rb
|
101
|
-
- examples/realtimeww2/.bashrc
|
102
|
-
- examples/realtimeww2/Gemfile
|
103
|
-
- examples/realtimeww2/Gemfile.lock
|
104
|
-
- examples/realtimeww2/main.rb
|
105
|
-
- examples/sexypizza/Gemfile
|
106
|
-
- examples/sexypizza/Gemfile.lock
|
107
|
-
- examples/sexypizza/main.rb
|
108
|
-
- examples/unisa/Gemfile
|
109
|
-
- examples/unisa/Gemfile.lock
|
110
|
-
- examples/unisa/main.rb
|
111
|
-
- examples/wallpaper/Gemfile
|
112
|
-
- examples/wallpaper/Gemfile.lock
|
113
|
-
- examples/wallpaper/main.rb
|
114
|
-
- examples/yayornay/Gemfile
|
115
|
-
- examples/yayornay/Gemfile.lock
|
116
|
-
- examples/yayornay/main.rb
|
117
48
|
- lib/reddit_bot.rb
|
118
49
|
- reddit_bot.gemspec
|
119
|
-
homepage:
|
50
|
+
homepage:
|
120
51
|
licenses:
|
121
52
|
- MIT
|
122
|
-
metadata:
|
53
|
+
metadata:
|
54
|
+
source_code_uri: https://github.com/Nakilon/reddit_bot
|
123
55
|
post_install_message:
|
124
56
|
rdoc_options: []
|
125
57
|
require_paths:
|
@@ -139,5 +71,5 @@ rubyforge_project:
|
|
139
71
|
rubygems_version: 2.5.2.3
|
140
72
|
signing_key:
|
141
73
|
specification_version: 4
|
142
|
-
summary:
|
74
|
+
summary: Simple library for Reddit bots
|
143
75
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# RedditBot
|
2
|
-
|
3
|
-
[![Join the chat at https://gitter.im/Nakilon/reddit_bot](https://badges.gitter.im/Nakilon/reddit_bot.svg)](https://gitter.im/Nakilon/reddit_bot)
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/reddit_bot.svg)](http://badge.fury.io/rb/reddit_bot)
|
5
|
-
|
6
|
-
### What
|
7
|
-
|
8
|
-
This library provides an easy way to run bots and scripts that use Reddit API.
|
9
|
-
I ([/u/nakilon](https://www.reddit.com/u/nakilon)) currently run near 10 bots with it.
|
10
|
-
|
11
|
-
### Why
|
12
|
-
|
13
|
-
Python (and so PRAW) sucks.
|
14
|
-
|
15
|
-
### Examples
|
16
|
-
|
17
|
-
I'm not usually publish every program (since there are thousand of them and adequate programmer knows that publishing everything is like throwing trash on street) but I'll add bots here so you could see how to use the library.
|
18
|
-
The [examples folder](examples) includes:
|
19
|
-
|
20
|
-
* **sexypizza** -- bot that updates wiki page with current flairs statistics
|
21
|
-
* **devflairbot** -- bot that flairs posts when some specifically flaired user comments there
|
22
|
-
* **mlgtv** -- bot that updates sidebar with currently streaming twitch channels
|
23
|
-
* **councilofricks** -- bot that flairs users according to Google Spreadsheet
|
24
|
-
* **wallpaper** -- bot that reports images with dimensions being not the same as in title
|
25
|
-
* **cptflairbot3** -- bot that sets user flair according to request submitted via web form
|
26
|
-
also publishes its activily log here http://www.nakilon.pro/casualpokemontrades/log.htm via Google Cloud Platform automations (Apps Script and Functions)
|
27
|
-
* **oneplus** -- bot that removes and modmails about links to 1080x1920 images
|
28
|
-
* **yayornay** -- bot that flairs posts according to voting in top level comments
|
29
|
-
* **realtimeww2** -- bot that posts tweets to a subreddit from a Twitter user timeline
|
30
|
-
* **johnnymarr** -- another Twitter timeline streaming bot working in the similar way
|
31
|
-
* **largeimages** -- this was my first bot -- it uses two approaches to track the most high resolution photos posted anywhere on Reddit to x-post them to [subreddit /r/largeimages](https://www.reddit.com/r/largeimages)
|
32
|
-
* **largeimagesreview** -- script that was used /r/largeimages to calculates quality of x-posts from different subreddits based on mods activity (remove/approve) so it showed that /r/pics and /r/foodporn should better be excluded:
|
33
|
-
|
34
|
-
pics Total: 98 Quality: 19%
|
35
|
-
wallpapers Total: 69 Quality: 52%
|
36
|
-
wallpaper Total: 45 Quality: 51%
|
37
|
-
woahdude Total: 30 Quality: 66%
|
38
|
-
CityPorn Total: 17 Quality: 82%
|
39
|
-
FoodPorn Total: 13 Quality: 7%
|
40
|
-
MapPorn Total: 13 Quality: 46%
|
41
|
-
SkyPorn Total: 11 Quality: 45%
|
42
|
-
carporn Total: 11 Quality: 45%
|
43
|
-
InfrastructurePorn Total: 9 Quality: 77%
|
44
|
-
|
45
|
-
EarthPorn Total: 23 Quality: 82% ✅⛔✅✅✅✅⛔✅✅✅✅✅⛔⛔✅✅✅✅✅✅✅✅✅
|
46
|
-
FoodPorn Total: 5 Quality: 0% ⛔⛔⛔⛔⛔
|
47
|
-
carporn Total: 4 Quality: 0% ⛔⛔⛔⛔
|
48
|
-
CityPorn Total: 4 Quality: 100% ✅✅✅✅
|
49
|
-
spaceporn Total: 4 Quality: 100% ✅✅✅✅
|
50
|
-
MapPorn Total: 4 Quality: 50% ✅⛔✅⛔
|
51
|
-
BotanicalPorn Total: 3 Quality: 66% ✅✅⛔
|
52
|
-
CemeteryPorn Total: 2 Quality: 0% ⛔⛔
|
53
|
-
MilitaryPorn Total: 2 Quality: 50% ✅⛔
|
54
|
-
DessertPorn Total: 2 Quality: 50% ⛔✅
|
55
|
-
pic Total: 2 Quality: 100% ✅✅
|
56
|
-
ArchitecturePorn Total: 2 Quality: 50% ✅⛔
|
57
|
-
AbandonedPorn Total: 2 Quality: 100% ✅✅
|
58
|
-
|
59
|
-
### Usage
|
60
|
-
|
61
|
-
$ gem install reddit_bot
|
62
|
-
|
63
|
-
or via Gemfile:
|
64
|
-
|
65
|
-
source "https://rubygems.org"
|
66
|
-
gem "reddit_bot"
|
67
|
-
|
68
|
-
helloworld.rb:
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
require "reddit_bot"
|
72
|
-
```
|
73
|
-
|
74
|
-
You obviously can't run these examples as is, because they use local configs that are not in git repo, like `secrets.yaml` file for Reddit authorization of the following format:
|
75
|
-
|
76
|
-
:client_id: Kb9.......6wBw
|
77
|
-
:client_secret: Fqo.....................AFI
|
78
|
-
:password: mybotpassword
|
79
|
-
:login: MyBotUsername
|
80
|
-
# :user_agent: optional_custom_useragent_to_bypass_reddit_spam_protection
|
81
|
-
|
82
|
-
To change log level:
|
83
|
-
|
84
|
-
```ruby
|
85
|
-
RedditBot.logger.level = Logger::ERROR
|
86
|
-
```
|
87
|
-
|
88
|
-
To update the gem version in Gemfile.lock when using Gemfile like this: `gem "reddit_bot", "~>1.1.0"`, do the:
|
89
|
-
|
90
|
-
$ bundle update reddit_bot
|
91
|
-
|
92
|
-
### Contributing and License
|
93
|
-
|
94
|
-
Bug reports and pull requests are welcome.
|
95
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
96
|
-
|
97
|
-
### TODO
|
98
|
-
|
99
|
-
* write more usage instructions here
|
100
|
-
* manual on how to create bots with Reddit web interface and run via bash console
|
101
|
-
* about NetHTTPUtils dependency; and that get_response returns String code not Integer like request_data
|
data/Rakefile
DELETED
data/examples/.bashrc
DELETED
data/examples/.gitignore
DELETED
data/examples/Gemfile.lock
DELETED
data/examples/boilerplate.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require_relative "../boilerplate"
|
2
|
-
|
3
|
-
BOT = RedditBot::Bot.new YAML.load_file "secrets.yaml"
|
4
|
-
SUBREDDIT = "CouncilOfRicks"
|
5
|
-
|
6
|
-
CSS_CLASS = "blueflair"
|
7
|
-
|
8
|
-
require "csv"
|
9
|
-
|
10
|
-
ignored = []
|
11
|
-
loop do
|
12
|
-
names, flairs = begin
|
13
|
-
JSON.load begin
|
14
|
-
NetHTTPUtils.request_data File.read "gas.url"
|
15
|
-
rescue NetHTTPUtils::Error => e
|
16
|
-
fail e unless [404, 500].include? e.code
|
17
|
-
puts "smth wrong with GAS script"
|
18
|
-
sleep 60
|
19
|
-
retry
|
20
|
-
end
|
21
|
-
rescue JSON::ParserError
|
22
|
-
puts "smth wrong with GAS script"
|
23
|
-
sleep 60
|
24
|
-
retry
|
25
|
-
end
|
26
|
-
|
27
|
-
existing = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist", limit: 1000)["users"]
|
28
|
-
fail if existing.size >= 1000
|
29
|
-
|
30
|
-
if names.size != flairs.size
|
31
|
-
puts "columns are different by length -- probably someone is editing the Spreadsheet"
|
32
|
-
else
|
33
|
-
names.zip(flairs).drop(1).map(&:flatten).map do |user, text|
|
34
|
-
user = user.to_s.strip
|
35
|
-
next unless user[/\A[a-z-_\d]+\z/i]
|
36
|
-
text = text.to_s.strip
|
37
|
-
next puts "ignored #{user}" if ignored.include? user
|
38
|
-
next if existing.include?( {"user"=>user, "flair_text"=>text, "flair_css_class"=>CSS_CLASS} )
|
39
|
-
[user, text, CSS_CLASS]
|
40
|
-
end.compact.each_slice(50) do |slice|
|
41
|
-
load = CSV.generate do |csv|
|
42
|
-
slice.each &csv.method(:<<)
|
43
|
-
end
|
44
|
-
BOT.json(:post, "/r/#{SUBREDDIT}/api/flaircsv", flair_csv: load).each do |report|
|
45
|
-
unless report.values_at("errors", "ok", "warnings") == [{}, true, {}]
|
46
|
-
pp report
|
47
|
-
abort "wrong keys" unless report.keys.sort == %w{ errors ok status warnings }
|
48
|
-
abort "wrong values" unless report.values_at(*%w{ ok status warnings }) == [false, "skipped", {}]
|
49
|
-
abort "wrong error keys" unless report["errors"].keys == %w{ user }
|
50
|
-
abort "wrong error values" unless user = report["errors"]["user"][/\Aunable to resolve user `([A-Za-z-_\d]+)', ignoring\z/, 1]
|
51
|
-
ignored |= [user]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
sleep 300
|
58
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
export LOGGING_KEYFILE=$GOOGLE_APPLICATION_CREDENTIALS_NAKILONPRO_LOGGING
|
@@ -1,13 +0,0 @@
|
|
1
|
-
function doGet(e) {
|
2
|
-
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
|
3
|
-
const range = sheet.getRange("A2:D100"); // hardcode
|
4
|
-
console.log(e.parameter.payload);
|
5
|
-
payload = JSON.parse(Utilities.newBlob(Utilities.base64Decode(e.parameter.payload)).getDataAsString());
|
6
|
-
range.moveTo(range.offset(1, 0));
|
7
|
-
sheet.getRange("A2:2").setValues( [ [
|
8
|
-
payload.messaged_at,
|
9
|
-
payload.processed_at,
|
10
|
-
payload.name,
|
11
|
-
payload.text,
|
12
|
-
] ] ); // hardcoded columns order
|
13
|
-
}
|
@@ -1,74 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git@github.com:Nakilon/gcplogger.git
|
3
|
-
revision: 7c1451fac49bd0d242c6de43315ae6e9a70d8f7f
|
4
|
-
specs:
|
5
|
-
gcplogger (0.1.1.0)
|
6
|
-
google-cloud-logging (~> 1.4.0)
|
7
|
-
public_suffix (~> 2.0)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
addressable (2.5.2)
|
13
|
-
public_suffix (>= 2.0.2, < 4.0)
|
14
|
-
faraday (0.15.2)
|
15
|
-
multipart-post (>= 1.2, < 3)
|
16
|
-
google-cloud-core (1.2.3)
|
17
|
-
google-cloud-env (~> 1.0)
|
18
|
-
google-cloud-env (1.0.2)
|
19
|
-
faraday (~> 0.11)
|
20
|
-
google-cloud-logging (1.4.0)
|
21
|
-
google-cloud-core (~> 1.1)
|
22
|
-
google-gax (~> 1.0)
|
23
|
-
stackdriver-core (~> 1.2)
|
24
|
-
google-gax (1.3.0)
|
25
|
-
google-protobuf (~> 3.2)
|
26
|
-
googleapis-common-protos (>= 1.3.5, < 2.0)
|
27
|
-
googleauth (~> 0.6.2)
|
28
|
-
grpc (>= 1.7.2, < 2.0)
|
29
|
-
rly (~> 0.2.3)
|
30
|
-
google-protobuf (3.6.1)
|
31
|
-
googleapis-common-protos (1.3.7)
|
32
|
-
google-protobuf (~> 3.0)
|
33
|
-
googleapis-common-protos-types (~> 1.0)
|
34
|
-
grpc (~> 1.0)
|
35
|
-
googleapis-common-protos-types (1.0.2)
|
36
|
-
google-protobuf (~> 3.0)
|
37
|
-
googleauth (0.6.6)
|
38
|
-
faraday (~> 0.12)
|
39
|
-
jwt (>= 1.4, < 3.0)
|
40
|
-
memoist (~> 0.12)
|
41
|
-
multi_json (~> 1.11)
|
42
|
-
os (>= 0.9, < 2.0)
|
43
|
-
signet (~> 0.7)
|
44
|
-
grpc (1.14.1)
|
45
|
-
google-protobuf (~> 3.1)
|
46
|
-
googleapis-common-protos-types (~> 1.0.0)
|
47
|
-
json (2.1.0)
|
48
|
-
jwt (1.5.6)
|
49
|
-
memoist (0.16.0)
|
50
|
-
multi_json (1.13.1)
|
51
|
-
multipart-post (2.0.0)
|
52
|
-
os (1.0.0)
|
53
|
-
public_suffix (2.0.5)
|
54
|
-
reddit_bot (1.3.0)
|
55
|
-
json
|
56
|
-
rly (0.2.3)
|
57
|
-
signet (0.9.0)
|
58
|
-
addressable (~> 2.3)
|
59
|
-
faraday (~> 0.9)
|
60
|
-
jwt (>= 1.5, < 3.0)
|
61
|
-
multi_json (~> 1.10)
|
62
|
-
stackdriver-core (1.3.0)
|
63
|
-
google-cloud-core (~> 1.2)
|
64
|
-
|
65
|
-
PLATFORMS
|
66
|
-
ruby
|
67
|
-
|
68
|
-
DEPENDENCIES
|
69
|
-
gcplogger!
|
70
|
-
jwt (< 2)
|
71
|
-
reddit_bot (~> 1.3.0)
|
72
|
-
|
73
|
-
BUNDLED WITH
|
74
|
-
1.16.1
|