reddit_bot 1.7.6 → 1.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/examples/dut/Gemfile +1 -0
- data/examples/dut/Gemfile.lock +5 -2
- data/examples/dut/main.rb +10 -8
- data/examples/largeimages/Gemfile +3 -3
- data/examples/largeimages/Gemfile.lock +12 -14
- data/examples/largeimages/main.rb +16 -19
- data/examples/unisa/Gemfile +1 -2
- data/examples/unisa/Gemfile.lock +5 -4
- data/examples/unisa/main.rb +10 -8
- data/lib/reddit_bot.rb +1 -8
- data/reddit_bot.gemspec +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 678fcb0251bf04be23802b62ddea29f5ea338386
|
4
|
+
data.tar.gz: b65667dea035f15f24a40f2c26017374b959780d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 384b4e42c38453c2a3ceb90892e144824f078f81dcc91e2c2ba65c39e22ed5e95d4b7ebc8bcba080d7113a10c654295768c8c6fcf32f7089495cd4395fafd80c
|
7
|
+
data.tar.gz: 24b3318a50e0ad0b784a8b8b1689ab3eef7dbebc1461760bc42a8fa920d6a223e2414910d2dfc38e5b50f394a1c032632d2aca87c12ba50141c1f07d941188dd
|
data/.gitignore
ADDED
data/examples/dut/Gemfile
CHANGED
data/examples/dut/Gemfile.lock
CHANGED
@@ -3,11 +3,11 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
addressable (2.7.0)
|
5
5
|
public_suffix (>= 2.0.2, < 5.0)
|
6
|
-
json (2.3.
|
6
|
+
json (2.3.1)
|
7
7
|
nethttputils (0.4.0.0)
|
8
8
|
addressable
|
9
9
|
public_suffix (4.0.5)
|
10
|
-
reddit_bot (1.7.
|
10
|
+
reddit_bot (1.7.6)
|
11
11
|
json
|
12
12
|
nethttputils (~> 0.4.0.0)
|
13
13
|
|
@@ -17,5 +17,8 @@ PLATFORMS
|
|
17
17
|
DEPENDENCIES
|
18
18
|
reddit_bot
|
19
19
|
|
20
|
+
RUBY VERSION
|
21
|
+
ruby 2.3.8p459
|
22
|
+
|
20
23
|
BUNDLED WITH
|
21
24
|
2.0.2
|
data/examples/dut/main.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require "reddit_bot"
|
2
2
|
subreddit = "dut".freeze
|
3
3
|
bot = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: subreddit
|
4
|
-
|
4
|
+
RedditBot::Twitter.init_twitter "DUT_Tweets"
|
5
5
|
|
6
6
|
loop do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
fail "no tweets found in subreddit" if id.zero? unless ENV["FIRST_RUN"]
|
11
|
-
|
12
|
-
fail unless flair = bot.json(:get, "/r/#{subreddit}/api/link_flair").find do |flair|
|
13
|
-
flair["text"] == "Twitter"
|
7
|
+
bot.json(:get, "/message/unread")["data"]["children"].each do |msg|
|
8
|
+
next unless %w{ nakilon technomod }.include? msg["data"]["author"]
|
9
|
+
abort "ordered to die" if %w{ die die } == msg["data"].values_at("subject", "body")
|
14
10
|
end
|
15
11
|
|
12
|
+
id = bot.new_posts.flat_map do |post|
|
13
|
+
post["selftext"].scan(/\(https:\/\/twitter\.com\/#{RedditBot::Twitter::TWITTER_ACCOUNT}\/status\/(\d{18,})\)/i).flatten.map(&:to_i).max
|
14
|
+
end.find(&:itself)
|
15
|
+
abort "no tweets found in subreddit" if id.zero? unless ENV["FIRST_RUN"]
|
16
|
+
abort "flair isn't available" unless flair = bot.json(:get, "/r/#{subreddit}/api/link_flair").find{ |flair| flair["text"] == "Twitter" }
|
17
|
+
|
16
18
|
timeline = RedditBot::Twitter.user_timeline
|
17
19
|
timeline.replace timeline.take 2 if ENV["FIRST_RUN"] # against 200 posts long flood
|
18
20
|
timeline.reverse_each do |tweet|
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
gem "json"
|
4
4
|
|
5
|
-
gem "nokogiri"
|
5
|
+
gem "nokogiri"
|
6
6
|
|
7
7
|
gem "nethttputils", git: "git@github.com:nakilon/nethttputils.git"
|
8
|
-
gem "directlink", "
|
8
|
+
gem "directlink", git: "git@github.com:nakilon/directlink.git"
|
9
9
|
|
10
|
-
gem "gcplogger", git: "git@github.com:nakilon/gcplogger.git"
|
10
|
+
gem "gcplogger", git: "git@github.com:nakilon/gcplogger.git"
|
11
11
|
gem "google-cloud-error_reporting"
|
@@ -7,22 +7,16 @@ GIT
|
|
7
7
|
google-cloud-logging (~> 1.4.0)
|
8
8
|
public_suffix (~> 2.0)
|
9
9
|
|
10
|
-
GIT
|
11
|
-
remote: git@github.com:nakilon/nethttputils.git
|
12
|
-
revision: 1eea987604cf592a62a6732eae864959f7a9fdc4
|
13
|
-
specs:
|
14
|
-
nethttputils (0.3.3.0)
|
15
|
-
|
16
10
|
GEM
|
17
11
|
remote: https://rubygems.org/
|
18
12
|
specs:
|
19
13
|
addressable (2.7.0)
|
20
14
|
public_suffix (>= 2.0.2, < 5.0)
|
21
|
-
directlink (0.0.
|
15
|
+
directlink (0.0.9.0)
|
22
16
|
addressable
|
23
17
|
fastimage (~> 2.1.3)
|
24
18
|
kramdown
|
25
|
-
nethttputils (~> 0.
|
19
|
+
nethttputils (~> 0.4.0.0)
|
26
20
|
nokogiri
|
27
21
|
reddit_bot (~> 1.7.0)
|
28
22
|
faraday (0.14.0)
|
@@ -67,7 +61,8 @@ GEM
|
|
67
61
|
googleauth (>= 0.5.1, < 0.7)
|
68
62
|
json (2.2.0)
|
69
63
|
jwt (2.1.0)
|
70
|
-
kramdown (2.
|
64
|
+
kramdown (2.3.0)
|
65
|
+
rexml
|
71
66
|
little-plugger (1.1.4)
|
72
67
|
logging (2.2.2)
|
73
68
|
little-plugger (~> 1.1)
|
@@ -76,13 +71,16 @@ GEM
|
|
76
71
|
mini_portile2 (2.4.0)
|
77
72
|
multi_json (1.13.1)
|
78
73
|
multipart-post (2.0.0)
|
74
|
+
nethttputils (0.4.0.0)
|
75
|
+
addressable
|
79
76
|
nokogiri (1.10.8)
|
80
77
|
mini_portile2 (~> 2.4.0)
|
81
78
|
os (0.9.6)
|
82
79
|
public_suffix (2.0.5)
|
83
|
-
reddit_bot (1.7.
|
80
|
+
reddit_bot (1.7.6)
|
84
81
|
json
|
85
|
-
nethttputils (~> 0.
|
82
|
+
nethttputils (~> 0.4.0.0)
|
83
|
+
rexml (3.2.4)
|
86
84
|
rly (0.2.3)
|
87
85
|
signet (0.8.1)
|
88
86
|
addressable (~> 2.3)
|
@@ -96,12 +94,12 @@ PLATFORMS
|
|
96
94
|
ruby
|
97
95
|
|
98
96
|
DEPENDENCIES
|
99
|
-
directlink (~> 0.0.
|
97
|
+
directlink (~> 0.0.9.0)
|
100
98
|
gcplogger!
|
101
99
|
google-cloud-error_reporting
|
102
100
|
json
|
103
|
-
nethttputils
|
104
|
-
nokogiri
|
101
|
+
nethttputils
|
102
|
+
nokogiri
|
105
103
|
|
106
104
|
BUNDLED WITH
|
107
105
|
2.0.2
|
@@ -16,7 +16,7 @@ require "directlink"
|
|
16
16
|
require "nokogiri"
|
17
17
|
|
18
18
|
require "../boilerplate"
|
19
|
-
|
19
|
+
bot = RedditBot::Bot.new YAML.load_file "secrets.yaml"
|
20
20
|
|
21
21
|
INCLUDE = %w{
|
22
22
|
user/kjoneslol/m/sfwpornnetwork
|
@@ -74,7 +74,7 @@ loop do
|
|
74
74
|
]
|
75
75
|
end ) ],
|
76
76
|
[:source_reddit, 30000000, ( INCLUDE.flat_map do |sortasub|
|
77
|
-
|
77
|
+
bot.new_posts(sortasub).take(100).map do |child|
|
78
78
|
next if child["is_self"]
|
79
79
|
next if EXCLUDE.include? child["subreddit"].downcase
|
80
80
|
child.values_at(
|
@@ -89,7 +89,7 @@ loop do
|
|
89
89
|
next if checked.include? id
|
90
90
|
checked << id
|
91
91
|
# next if Gem::Platform.local.os == "darwin" # prevent concurrent posting
|
92
|
-
logger.
|
92
|
+
logger.debug "image url for #{id}: #{url}"
|
93
93
|
next logger.warn "skipped a post by /u/sjhill" if author == "sjhill" # opt-out
|
94
94
|
next logger.warn "skipped a post by /u/redisforever" if author == "redisforever" # opt-out
|
95
95
|
next logger.warn "skipped a post by /u/bekalaki" if author == "bekalaki" # 9 ways to divide a karmawhore
|
@@ -104,27 +104,24 @@ loop do
|
|
104
104
|
|
105
105
|
t = begin
|
106
106
|
DirectLink url, 60
|
107
|
-
rescue
|
108
|
-
Net::OpenTimeout,
|
109
|
-
Errno::ECONNRESET,
|
110
|
-
NetHTTPUtils::Error,
|
111
|
-
FastImage::UnknownImageType,
|
112
|
-
FastImage::ImageFetchFailure,
|
113
|
-
DirectLink::ErrorNotFound,
|
114
|
-
DirectLink::ErrorBadLink => e
|
107
|
+
rescue *DirectLink::NORMAL_EXCEPTIONS => e
|
115
108
|
next logger.error "skipped (#{e}) #{url} from http://redd.it/#{id}"
|
116
109
|
end
|
117
110
|
logger.debug "DirectLink: #{t.inspect}"
|
118
111
|
tt = t.is_a?(Array) ? t : [t]
|
119
112
|
next logger.error "probably crosspost of a self post: http://redd.it/#{id}" if tt.empty?
|
120
|
-
unless min_resolution <= tt.first.width * tt.first.height
|
121
|
-
next logger.info "skipped low resolution #{source}"
|
122
|
-
end
|
113
|
+
next logger.info "skipped low resolution #{source}" unless min_resolution <= tt.first.width * tt.first.height
|
123
114
|
# puts "https://www.reddit.com/r/LargeImages/search.json?q=url%3A#{CGI.escape url}&restrict_sr=on"
|
124
115
|
resolution = "[#{tt.first.width}x#{tt.first.height}]"
|
125
|
-
next logger.warn "already submitted #{resolution} #{id}: '#{url}'" unless
|
126
|
-
|
127
|
-
|
116
|
+
next logger.warn "already submitted #{resolution} #{id}: '#{url}'" unless Gem::Platform.local.os == "darwin" || search_url[url].empty?
|
117
|
+
|
118
|
+
system "curl -s '#{tt.first.url}' -o temp --retry 5" or fail
|
119
|
+
next logger.warn "skipped <2mb id=#{id}" if 2000000 > File.size("temp")
|
120
|
+
if "mapporn" == subreddit.downcase
|
121
|
+
`vips pngsave temp temp.png`
|
122
|
+
next logger.warn "skipped /r/mapporn <10mb PNG id=#{id}" if 10000000 > File.size("temp.png")
|
123
|
+
end
|
124
|
+
|
128
125
|
title = "#{resolution}#{
|
129
126
|
" [#{tt.size} images]" if tt.size > 1
|
130
127
|
} #{
|
@@ -133,7 +130,7 @@ loop do
|
|
133
130
|
} /r/#{subreddit}".gsub(/\s+\(\s+\)\s+/, " ").sub(/(?<=.{297}).+/, "...")
|
134
131
|
logger.warn "new post #{source}: #{url} #{title.inspect}"
|
135
132
|
unless Gem::Platform.local.os == "darwin"
|
136
|
-
result =
|
133
|
+
result = bot.json :post,
|
137
134
|
"/api/submit",
|
138
135
|
{
|
139
136
|
kind: "link",
|
@@ -160,7 +157,7 @@ loop do
|
|
160
157
|
text = [line1, line2, line3].compact.join(" \n")
|
161
158
|
logger.info "new comment: #{text.inspect}"
|
162
159
|
unless Gem::Platform.local.os == "darwin"
|
163
|
-
result =
|
160
|
+
result = bot.leave_a_comment "#{result["json"]["data"]["name"]}", text.sub(/(?<=.{9000}).+/m, "...")
|
164
161
|
unless result["json"]["errors"].empty?
|
165
162
|
logger.error result.inspect
|
166
163
|
fail "failed to leave comment"
|
data/examples/unisa/Gemfile
CHANGED
data/examples/unisa/Gemfile.lock
CHANGED
@@ -3,12 +3,11 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
addressable (2.7.0)
|
5
5
|
public_suffix (>= 2.0.2, < 5.0)
|
6
|
-
|
7
|
-
json (2.3.0)
|
6
|
+
json (2.3.1)
|
8
7
|
nethttputils (0.4.0.0)
|
9
8
|
addressable
|
10
9
|
public_suffix (4.0.5)
|
11
|
-
reddit_bot (1.7.
|
10
|
+
reddit_bot (1.7.6)
|
12
11
|
json
|
13
12
|
nethttputils (~> 0.4.0.0)
|
14
13
|
|
@@ -16,8 +15,10 @@ PLATFORMS
|
|
16
15
|
ruby
|
17
16
|
|
18
17
|
DEPENDENCIES
|
19
|
-
byebug
|
20
18
|
reddit_bot
|
21
19
|
|
20
|
+
RUBY VERSION
|
21
|
+
ruby 2.3.8p459
|
22
|
+
|
22
23
|
BUNDLED WITH
|
23
24
|
2.0.2
|
data/examples/unisa/main.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require "reddit_bot"
|
2
2
|
subreddit = "unisa".freeze
|
3
3
|
bot = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: subreddit
|
4
|
-
|
4
|
+
RedditBot::Twitter.init_twitter "unisa"
|
5
5
|
|
6
6
|
loop do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
fail "no tweets found in subreddit" if id.zero? unless ENV["FIRST_RUN"]
|
11
|
-
|
12
|
-
fail unless flair = bot.json(:get, "/r/#{subreddit}/api/link_flair").find do |flair|
|
13
|
-
flair["text"] == "Twitter"
|
7
|
+
bot.json(:get, "/message/unread")["data"]["children"].each do |msg|
|
8
|
+
next unless %w{ nakilon technomod }.include? msg["data"]["author"]
|
9
|
+
abort "ordered to die" if %w{ die die } == msg["data"].values_at("subject", "body")
|
14
10
|
end
|
15
11
|
|
12
|
+
id = bot.new_posts.flat_map do |post|
|
13
|
+
post["selftext"].scan(/\(https:\/\/twitter\.com\/#{RedditBot::Twitter::TWITTER_ACCOUNT}\/status\/(\d{18,})\)/i).flatten.map(&:to_i).max
|
14
|
+
end.find(&:itself)
|
15
|
+
abort "no tweets found in subreddit" if id.zero? unless ENV["FIRST_RUN"]
|
16
|
+
abort "flair isn't available" unless flair = bot.json(:get, "/r/#{subreddit}/api/link_flair").find{ |flair| flair["text"] == "Twitter" }
|
17
|
+
|
16
18
|
timeline = RedditBot::Twitter.user_timeline
|
17
19
|
timeline.replace timeline.take 2 if ENV["FIRST_RUN"] # against 200 posts long flood
|
18
20
|
timeline.reverse_each do |tweet|
|
data/lib/reddit_bot.rb
CHANGED
@@ -301,14 +301,7 @@ module RedditBot
|
|
301
301
|
"https://api.twitter.com/1.1/statuses/user_timeline.json",
|
302
302
|
form: { screen_name: TWITTER_ACCOUNT, count: 200, tweet_mode: "extended" },
|
303
303
|
header: { Authorization: "Bearer #{TWITTER_ACCESS_TOKEN}" }
|
304
|
-
)
|
305
|
-
next unless res.key? "x-rate-limit-remaining"
|
306
|
-
remaining = res.fetch("x-rate-limit-remaining").to_i
|
307
|
-
next if 100 < remaining
|
308
|
-
t = (res.fetch("x-rate-limit-reset").to_i - Time.now.to_i + 1).fdiv remaining
|
309
|
-
puts "sleep #{t}"
|
310
|
-
sleep t
|
311
|
-
end
|
304
|
+
)
|
312
305
|
rescue NetHTTPUtils::Error => e
|
313
306
|
fail unless [500, 503].include? e.code
|
314
307
|
sleep timeout
|
data/reddit_bot.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "reddit_bot"
|
3
|
-
spec.version = "1.7.
|
3
|
+
spec.version = "1.7.7"
|
4
4
|
spec.authors = ["Victor Maslov"]
|
5
5
|
spec.email = ["nakilon@gmail.com"]
|
6
6
|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
# spec.require_paths = ["lib"]
|
14
14
|
|
15
15
|
spec.add_runtime_dependency "json"
|
16
|
-
spec.add_runtime_dependency "nethttputils", "~>0.4.
|
16
|
+
spec.add_runtime_dependency "nethttputils", "~>0.4.1.0"
|
17
17
|
# spec.add_development_dependency "bundler", "~> 1.11"
|
18
18
|
# spec.add_development_dependency "rake", "~> 10.0"
|
19
19
|
# spec.add_development_dependency "rspec", "~> 3.0"
|
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: 1.7.
|
4
|
+
version: 1.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.4.
|
33
|
+
version: 0.4.1.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.
|
40
|
+
version: 0.4.1.0
|
41
41
|
description: better than PRAW
|
42
42
|
email:
|
43
43
|
- nakilon@gmail.com
|
@@ -45,6 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".gitignore"
|
48
49
|
- Gemfile
|
49
50
|
- LICENSE.txt
|
50
51
|
- README.md
|