reddit_bot 1.7.5 → 1.7.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 +4 -4
- data/examples/dut/Gemfile +3 -0
- data/examples/dut/Gemfile.lock +21 -0
- data/examples/dut/main.rb +39 -0
- data/examples/unisa/Gemfile +5 -0
- data/examples/unisa/Gemfile.lock +23 -0
- data/examples/unisa/main.rb +39 -0
- data/lib/reddit_bot.rb +2 -4
- data/reddit_bot.gemspec +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52b34b7ffbd747f455238139479414c4c73575e3
|
4
|
+
data.tar.gz: 7b08991727037d0f91bcecfb7bca40caa5e33b81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ee3c17c7ce2683ca7bfce42f50bdde6af718de47a1b1093f37e9efcc6a49181574dd7d9d6222f58a76348235f5b4da58f416c4888e78e51c3f2067cc3745199
|
7
|
+
data.tar.gz: 5fb5186be0faeda8b551cac5354c2d558d2972cfb41631f48feca0bd0c975bfb8626305d1bed292805ae8a128864679b531b474f3151f0019a31645604cc2e8c
|
@@ -0,0 +1,21 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.7.0)
|
5
|
+
public_suffix (>= 2.0.2, < 5.0)
|
6
|
+
json (2.3.0)
|
7
|
+
nethttputils (0.4.0.0)
|
8
|
+
addressable
|
9
|
+
public_suffix (4.0.5)
|
10
|
+
reddit_bot (1.7.5)
|
11
|
+
json
|
12
|
+
nethttputils (~> 0.4.0.0)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
reddit_bot
|
19
|
+
|
20
|
+
BUNDLED WITH
|
21
|
+
2.0.2
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "reddit_bot"
|
2
|
+
subreddit = "dut".freeze
|
3
|
+
bot = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: subreddit
|
4
|
+
twitter = RedditBot::Twitter.init_twitter "DUT_Tweets"
|
5
|
+
|
6
|
+
loop do
|
7
|
+
id = bot.new_posts.find do |post|
|
8
|
+
/\(https:\/\/twitter\.com\/#{RedditBot::Twitter::TWITTER_ACCOUNT}\/status\/(\d{18,})\)/i =~ post["selftext"] and break $1
|
9
|
+
end.to_i
|
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"
|
14
|
+
end
|
15
|
+
|
16
|
+
timeline = RedditBot::Twitter.user_timeline
|
17
|
+
timeline.replace timeline.take 2 if ENV["FIRST_RUN"] # against 200 posts long flood
|
18
|
+
timeline.reverse_each do |tweet|
|
19
|
+
next if tweet["id"] <= id
|
20
|
+
title, text, _ = RedditBot::Twitter.tweet2titleNtext tweet
|
21
|
+
result = bot.json :post, "/api/submit", {
|
22
|
+
sr: subreddit,
|
23
|
+
kind: "self",
|
24
|
+
title: title,
|
25
|
+
text: text,
|
26
|
+
flair_id: flair["id"],
|
27
|
+
}
|
28
|
+
p result
|
29
|
+
if result["json"]["errors"].empty?
|
30
|
+
abort "OK" if ENV["ONCE"]
|
31
|
+
next
|
32
|
+
end
|
33
|
+
fail unless result["json"]["errors"].map(&:first) == ["ALREADY_SUB"]
|
34
|
+
puts "ALREADY_SUB error for #{tweet["id"]}"
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "END LOOP #{Time.now}"
|
38
|
+
sleep 300
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.7.0)
|
5
|
+
public_suffix (>= 2.0.2, < 5.0)
|
6
|
+
byebug (11.0.1)
|
7
|
+
json (2.3.0)
|
8
|
+
nethttputils (0.4.0.0)
|
9
|
+
addressable
|
10
|
+
public_suffix (4.0.5)
|
11
|
+
reddit_bot (1.7.5)
|
12
|
+
json
|
13
|
+
nethttputils (~> 0.4.0.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
byebug
|
20
|
+
reddit_bot
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
2.0.2
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "reddit_bot"
|
2
|
+
subreddit = "unisa".freeze
|
3
|
+
bot = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: subreddit
|
4
|
+
twitter = RedditBot::Twitter.init_twitter "unisa"
|
5
|
+
|
6
|
+
loop do
|
7
|
+
id = bot.new_posts.find do |post|
|
8
|
+
/\(https:\/\/twitter\.com\/#{RedditBot::Twitter::TWITTER_ACCOUNT}\/status\/(\d{18,})\)/i =~ post["selftext"] and break $1
|
9
|
+
end.to_i
|
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"
|
14
|
+
end
|
15
|
+
|
16
|
+
timeline = RedditBot::Twitter.user_timeline
|
17
|
+
timeline.replace timeline.take 2 if ENV["FIRST_RUN"] # against 200 posts long flood
|
18
|
+
timeline.reverse_each do |tweet|
|
19
|
+
next if tweet["id"] <= id
|
20
|
+
title, text, _ = RedditBot::Twitter.tweet2titleNtext tweet
|
21
|
+
result = bot.json :post, "/api/submit", {
|
22
|
+
sr: subreddit,
|
23
|
+
kind: "self",
|
24
|
+
title: title,
|
25
|
+
text: text,
|
26
|
+
flair_id: flair["id"],
|
27
|
+
}
|
28
|
+
p result
|
29
|
+
if result["json"]["errors"].empty?
|
30
|
+
abort "OK" if ENV["ONCE"]
|
31
|
+
next
|
32
|
+
end
|
33
|
+
fail unless result["json"]["errors"].map(&:first) == ["ALREADY_SUB"]
|
34
|
+
puts "ALREADY_SUB error for #{tweet["id"]}"
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "END LOOP #{Time.now}"
|
38
|
+
sleep 300
|
39
|
+
end
|
data/lib/reddit_bot.rb
CHANGED
@@ -7,8 +7,6 @@ require "yaml"
|
|
7
7
|
|
8
8
|
require "nethttputils"
|
9
9
|
|
10
|
-
require_relative "reddit_bot/version" # TODO: deprecate this
|
11
|
-
|
12
10
|
module RedditBot
|
13
11
|
require "logger"
|
14
12
|
class << self
|
@@ -205,7 +203,7 @@ module RedditBot
|
|
205
203
|
username: @name,
|
206
204
|
password: @secret_password,
|
207
205
|
}, {
|
208
|
-
"User-Agent" => "bot/#{@user_agent || @name}/#{
|
206
|
+
"User-Agent" => "bot/#{@user_agent || @name}/#{Gem::Specification::load("#{__dir__}/../reddit_bot.gemspec").version} by /u/nakilon",
|
209
207
|
}, @secret_auth
|
210
208
|
unless @token_cached = response["access_token"]
|
211
209
|
fail "bot #{@name} isn't a 'developer' of app at https://www.reddit.com/prefs/apps/" if response == {"error"=>"invalid_grant"}
|
@@ -232,7 +230,7 @@ module RedditBot
|
|
232
230
|
begin
|
233
231
|
reddit_resp mtd, "https://oauth.reddit.com" + path, form, {
|
234
232
|
"Authorization" => "bearer #{token}",
|
235
|
-
"User-Agent" => "bot/#{@user_agent || @name}/#{
|
233
|
+
"User-Agent" => "bot/#{@user_agent || @name}/#{Gem::Specification::load("#{__dir__}/../reddit_bot.gemspec").version} by /u/nakilon",
|
236
234
|
}
|
237
235
|
rescue NetHTTPUtils::Error => e
|
238
236
|
raise unless e.code == 401
|
data/reddit_bot.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
@@ -72,6 +72,9 @@ files:
|
|
72
72
|
- examples/devflairbot/Gemfile
|
73
73
|
- examples/devflairbot/Gemfile.lock
|
74
74
|
- examples/devflairbot/main.rb
|
75
|
+
- examples/dut/Gemfile
|
76
|
+
- examples/dut/Gemfile.lock
|
77
|
+
- examples/dut/main.rb
|
75
78
|
- examples/get_dimensions.rb
|
76
79
|
- examples/iostroubleshooting/Gemfile
|
77
80
|
- examples/iostroubleshooting/Gemfile.lock
|
@@ -101,6 +104,9 @@ files:
|
|
101
104
|
- examples/sexypizza/Gemfile
|
102
105
|
- examples/sexypizza/Gemfile.lock
|
103
106
|
- examples/sexypizza/main.rb
|
107
|
+
- examples/unisa/Gemfile
|
108
|
+
- examples/unisa/Gemfile.lock
|
109
|
+
- examples/unisa/main.rb
|
104
110
|
- examples/wallpaper/Gemfile
|
105
111
|
- examples/wallpaper/Gemfile.lock
|
106
112
|
- examples/wallpaper/main.rb
|