reddit_bot 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d5d8b67897b7209d414d028292be3e5e2f42bb7
4
- data.tar.gz: 7cf575284c8ae0be2f275814aa3dd8d25646d035
3
+ metadata.gz: 2755905b475ba61672aece5ce430f31a391fd314
4
+ data.tar.gz: a7e4323f4030e6277c26e5d0601636b3ed2eaaf8
5
5
  SHA512:
6
- metadata.gz: 6467d5467979d606bd390896716cf7421f650f19f4f2999925cd119371e5ff1edbbc21e8f04e525f86655ee3376d6e8f59f56df63aab962f71af94a6d2fea1fc
7
- data.tar.gz: 38b77df442843e676b92594ee968b9b151542963e02b20e79608dce36ea2120460c06095d45b79ab127923c378bc3ca3773f40a65a1c926ac8bdd245d3d6d854
6
+ metadata.gz: f071f2c06e1fb887e2dfd1f6ee02ee2f12848bec73006393b45a2fda6ac8c03e08f0412ba3eb6fe2f69d2d7aacd2fd8f06141d655153fb4f35797097bc47746a
7
+ data.tar.gz: a6a91942b6c51a109af10b0618f9cb42406bd53e2534b4c3ec93b5e77a579bfe92646464d03a5052ad33792ce65beff0b2fcd6616835acc44442e6bf392f47e8
data/README.md CHANGED
@@ -16,12 +16,16 @@ Python (and so PRAW) sucks.
16
16
 
17
17
  The [examples folder](examples) includes:
18
18
 
19
- * iostroubleshooting -- bot that applies flairs to posts
19
+ * sexypizza -- bot that updates wiki page with current flairs statistics
20
20
  * mlgtv -- bot that updates sidebar with currently streaming twitch channels
21
+ * flairmotron -- bot that flairs users according to Google Spreadsheet
22
+ * devflairbot -- bot that flairs posts when some specifically flaired user comments there
21
23
  * pokemon_trading -- bot that sets flair to user according to request submitted via PM
24
+ * iostroubleshooting -- bot that applies flairs to posts (subreddit seems to be suspended)
22
25
  * oneplus -- bot that removes and modmails about links to 1080x1920 images
23
- * yayornay (not active yet) -- bot that flairs posts according to voting in top level comments
24
- * largeimages -- useful script for [subreddit /r/largeimages](https://reddit.com/r/largeimages/top)
26
+ * wallpaper -- bot that reports images with dimensions not the same as in title
27
+ * yayornay -- bot that flairs posts according to voting in top level comments
28
+ * largeimagesreview -- useful script for [subreddit /r/largeimages](https://reddit.com/r/largeimages/top)
25
29
  It calculates quality of x-posts from different subreddits based on mods activity (remove/approve).
26
30
  For example, this shows that it would be ok to ignore /r/pics from now:
27
31
 
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "reddit_bot", "~>1.1.5"
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ json (1.8.3)
5
+ reddit_bot (1.1.5)
6
+ json
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ reddit_bot (~> 1.1.5)
13
+
14
+ BUNDLED WITH
15
+ 1.11.2
@@ -0,0 +1,53 @@
1
+ require_relative "../boilerplate"
2
+
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true#, subreddit: SUBREDDIT
4
+
5
+
6
+ loop do
7
+ AWSStatus::touch
8
+ puts "LOOP #{Time.now}"
9
+
10
+ [
11
+ ["ion", "Developer"],
12
+ ["survivetheculling", "Developer"],
13
+ ].each do |subreddit, developer_class|
14
+ puts subreddit
15
+
16
+ JSON.parse(
17
+ DownloadWithRetry::download_with_retry("https://www.reddit.com/r/#{subreddit}/comments.json")
18
+ )["data"]["children"].each do |comment|
19
+ id = comment["data"]["link_id"][3..-1]
20
+ commenter_flair = comment["data"]["author_flair_css_class"]
21
+ puts commenter_flair if commenter_flair
22
+ next 'puts "skip"' unless developer_class == commenter_flair
23
+ puts "https://reddit.com/r/#{subreddit}/comments/#{id}/#{comment["data"]["id"]} '#{commenter_flair}'"
24
+ flairselector = BOT.json :post, "/api/flairselector", { link: comment["data"]["link_id"] }
25
+ existing_flair_class = flairselector["current"]["flair_css_class"]
26
+ puts "https://reddit.com/#{id} '#{existing_flair_class}'"
27
+ next unless target = case existing_flair_class
28
+ when nil then "untaggeddev"
29
+ when "news" then "newsdev"
30
+ when "discussion" then "discussiondev"
31
+ when "media" then "mediadev"
32
+ when "feedback" then "feedbackdev"
33
+ when "question" then "questiondev"
34
+ when "bug" then "bugdev"
35
+ when "announcement" then "announcementdev"
36
+ when "suggestion" then "suggestiondev"
37
+ else puts "ignored https://reddit.com/#{id} '#{existing_flair_class}'"
38
+ end
39
+ choice = flairselector["choices"].find{ |choice| choice["flair_css_class"] == target }
40
+ puts "assigning '#{target}' (#{choice}) flair to post https://reddit.com/#{id}"
41
+ _ = BOT.json :post,
42
+ "/api/selectflair", {
43
+ flair_template_id: choice["flair_template_id"],
44
+ link: comment["data"]["link_id"],
45
+ }
46
+ fail _.inspect unless _ == {"json"=>{"errors"=>[]}}
47
+ end
48
+
49
+ end
50
+
51
+ puts "END LOOP #{Time.now}"
52
+ sleep 60
53
+ end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "reddit_bot", "~>1.1.5"
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ json (1.8.3)
5
+ reddit_bot (1.1.5)
6
+ json
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ reddit_bot (~> 1.1.5)
13
+
14
+ BUNDLED WITH
15
+ 1.11.2
@@ -0,0 +1,43 @@
1
+ require_relative "../boilerplate"
2
+
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true#, subreddit: SUBREDDIT
4
+ SUBREDDIT = "CouncilOfRicks"
5
+
6
+ CSS_CLASS = "blueflair"
7
+
8
+ # require "open-uri"
9
+ # require "json"
10
+ require "csv"
11
+
12
+ loop do
13
+ AWSStatus::touch
14
+
15
+ names, flairs = begin
16
+ JSON.parse DownloadWithRetry::download_with_retry File.read "gas.url"
17
+ rescue JSON::ParserError
18
+ puts "smth wrong with GAS script"
19
+ sleep 60
20
+ retry
21
+ end
22
+
23
+ existing = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist", limit: 1000)["users"]
24
+
25
+ if names.size == flairs.size
26
+ names.zip(flairs).drop(1).map(&:flatten).each_slice(50) do |slice|
27
+ CSV(load = "") do |csv|
28
+ slice.each do |user, text|
29
+ user = user.to_s.strip
30
+ text = text.to_s.strip
31
+ csv << [user, text, CSS_CLASS] unless existing.include?( {"user"=>user, "flair_text"=>text, "flair_css_class"=>CSS_CLASS} )
32
+ end
33
+ end
34
+ BOT.json(:post, "/r/#{SUBREDDIT}/api/flaircsv", [["flair_csv", load]]).each do |report|
35
+ pp report unless report.values_at("errors", "ok", "warnings") == [{}, true, {}]
36
+ end
37
+ end
38
+ else
39
+ puts "columns are different by length"
40
+ end
41
+
42
+ sleep 300
43
+ end
@@ -2,4 +2,4 @@
2
2
 
3
3
  # ruby "2.0.0"
4
4
  gem "json"#, "1.7.7"
5
- gem "reddit_bot", "0.1.3"
5
+ gem "reddit_bot", "~>1.1.5"
@@ -2,7 +2,7 @@ GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
4
  json (1.8.3)
5
- reddit_bot (0.1.3)
5
+ reddit_bot (1.1.5)
6
6
  json
7
7
 
8
8
  PLATFORMS
@@ -10,7 +10,7 @@ PLATFORMS
10
10
 
11
11
  DEPENDENCIES
12
12
  json
13
- reddit_bot (= 0.1.3)
13
+ reddit_bot (~> 1.1.5)
14
14
 
15
15
  BUNDLED WITH
16
16
  1.11.2
@@ -1,4 +1,5 @@
1
1
  require_relative File.join "..", "boilerplate"
2
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
2
3
 
3
4
  # SUBREDDIT = "test___________"
4
5
  SUBREDDIT = "iostroubleshooting"
@@ -10,7 +11,7 @@ loop do
10
11
  AWSStatus::touch
11
12
  catch :loop do
12
13
 
13
- existing = RedditBot.json(:get, "/r/#{SUBREDDIT}/api/flairlist")["users"]
14
+ existing = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist")["users"]
14
15
  begin
15
16
  JSON.parse(DownloadWithRetry::download_with_retry("#{File.read "gas.url"}sheet_name=Bot&spreadsheet_id=10UzXUbawBgXLQkxXDMz28Qcx3IQPjwG9nByd_d8y31I", &:read))
16
17
  rescue JSON::ParserError
@@ -25,7 +26,7 @@ loop do
25
26
  end.compact.each_slice(50) do |slice|
26
27
  CSV(load = ""){ |csv| slice.each{ |record| csv << record } }
27
28
  puts load
28
- RedditBot.json(:post, "/r/#{SUBREDDIT}/api/flaircsv", [["flair_csv", load]]).each do |report|
29
+ BOT.json(:post, "/r/#{SUBREDDIT}/api/flaircsv", [["flair_csv", load]]).each do |report|
29
30
  pp report unless report.values_at("errors", "ok", "warnings") == [{}, true, {}]
30
31
  end
31
32
  end
File without changes
@@ -1,15 +1,17 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
+ json (1.8.3)
4
5
  mll (2.2.1)
5
- reddit_bot (0.1.0)
6
+ reddit_bot (1.1.5)
7
+ json
6
8
 
7
9
  PLATFORMS
8
10
  ruby
9
11
 
10
12
  DEPENDENCIES
11
13
  mll
12
- reddit_bot
14
+ reddit_bot (= 1.1.5)
13
15
 
14
16
  BUNDLED WITH
15
17
  1.11.2
@@ -8,13 +8,15 @@ end
8
8
 
9
9
 
10
10
  require_relative File.join "..", "boilerplate"
11
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
12
+
11
13
  SUBREDDIT = "largeimages"
12
14
 
13
15
  table = cache.call do
14
- RedditBot.json(:get, "/r/#{SUBREDDIT}/about/log", [["limit", 500]])["data"]["children"].map do |child|
16
+ BOT.json(:get, "/r/#{SUBREDDIT}/about/log", [["limit", 10]])["data"]["children"].map do |child|
15
17
  fail child unless child["kind"] == "modaction"
16
18
  next unless %w{ removelink approvelink }.include? child["data"]["action"]
17
- title = RedditBot.json(:get, "/api/info", [["id", child["data"]["target_fullname"]]])["data"]["children"][0]["data"]["title"]
19
+ title = BOT.json(:get, "/api/info", [["id", child["data"]["target_fullname"]]])["data"]["children"][0]["data"]["title"]
18
20
  [child["data"]["action"], title[/(?<=^\[)\d+x\d+/], title[/[^\/]+$/]]
19
21
  end.compact
20
22
  end
@@ -1,3 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "reddit_bot", "~>1.0"
3
+ gem "reddit_bot", "~>1.1.5"
@@ -2,14 +2,14 @@ GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
4
  json (1.8.3)
5
- reddit_bot (1.0.0)
5
+ reddit_bot (1.1.5)
6
6
  json
7
7
 
8
8
  PLATFORMS
9
9
  ruby
10
10
 
11
11
  DEPENDENCIES
12
- reddit_bot
12
+ reddit_bot (~> 1.1.5)
13
13
 
14
14
  BUNDLED WITH
15
15
  1.11.2
@@ -1,9 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- if ENV["LOGNAME"] == "nakilon"
4
- gem "reddit_bot", "~>1.0", path: File.join("..", "..")
5
- else
6
- gem "reddit_bot", "~>1.0"
7
- end
3
+ # if ENV["LOGNAME"] == "nakilon"
4
+ # gem "reddit_bot", "~>1.0", path: File.join("..", "..")
5
+ # else
6
+ gem "reddit_bot", "~>1.1.5"
7
+ # end
8
8
 
9
9
  gem "fastimage", "1.7.0"
@@ -1,9 +1,3 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- reddit_bot (1.1.1)
5
- json
6
-
7
1
  GEM
8
2
  remote: https://rubygems.org/
9
3
  specs:
@@ -11,13 +5,15 @@ GEM
11
5
  fastimage (1.7.0)
12
6
  addressable (~> 2.3, >= 2.3.5)
13
7
  json (1.8.3)
8
+ reddit_bot (1.1.5)
9
+ json
14
10
 
15
11
  PLATFORMS
16
12
  ruby
17
13
 
18
14
  DEPENDENCIES
19
15
  fastimage (= 1.7.0)
20
- reddit_bot (~> 1.0)!
16
+ reddit_bot (~> 1.1.5)
21
17
 
22
18
  BUNDLED WITH
23
19
  1.11.2
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- if ENV["LOGNAME"] == "nakilon"
4
- gem "reddit_bot", "~>1.0", path: File.join("..", "..")
5
- else
6
- gem "reddit_bot", "~>1.0"
7
- end
3
+ # if ENV["LOGNAME"] == "nakilon"
4
+ # gem "reddit_bot", "~>1.1.5", path: File.join("..", "..")
5
+ # else
6
+ gem "reddit_bot", "~>1.1.5"
7
+ # end
@@ -1,19 +1,15 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- reddit_bot (1.0.0)
5
- json
6
-
7
1
  GEM
8
2
  remote: https://rubygems.org/
9
3
  specs:
10
4
  json (1.8.3)
5
+ reddit_bot (1.1.5)
6
+ json
11
7
 
12
8
  PLATFORMS
13
9
  ruby
14
10
 
15
11
  DEPENDENCIES
16
- reddit_bot (~> 1.0)!
12
+ reddit_bot (~> 1.1.5)
17
13
 
18
14
  BUNDLED WITH
19
15
  1.11.2
@@ -1,6 +1,5 @@
1
1
  require_relative File.join "..", "boilerplate"
2
-
3
- BOT = RedditBot::Bot.new YAML.load(File.read "secrets"), ignore_captcha: true
2
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
4
3
 
5
4
  loop do
6
5
  AWSStatus::touch
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "reddit_bot", "~>1.1.5"
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ json (1.8.3)
5
+ reddit_bot (1.1.5)
6
+ json
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ reddit_bot (~> 1.1.5)
13
+
14
+ BUNDLED WITH
15
+ 1.11.2
@@ -0,0 +1,29 @@
1
+ require_relative "../boilerplate"
2
+
3
+ SUBREDDIT = "sexypizza"
4
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true#, subreddit: SUBREDDIT
5
+
6
+
7
+ loop do
8
+ AWSStatus::touch
9
+ puts "LOOP #{Time.now}"
10
+
11
+ flairs = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist", {limit: 1000})["users"]
12
+
13
+ text = \
14
+ "**Vote with your flair!**\n\n" +
15
+ "Type of pizza | Number of lovers\n" +
16
+ "--------------|-----------------\n" +
17
+ flairs.
18
+ group_by{ |flair| flair["flair_text"] }.
19
+ # reject{ |flair, | flair.empty? }.
20
+ sort_by{ |_, group| -group.size }.
21
+ map{ |flair, group| "#{flair} | #{group.size}" }.
22
+ # map{ |flair, group| "#{flair} | #{group.size} | #{group.map{ |u| u["user"] }.join ", "}" }.
23
+ join("\n")
24
+ puts text
25
+
26
+ p BOT.wiki_edit SUBREDDIT, "toppings", text
27
+
28
+ sleep 3600
29
+ end
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # gem "json", "1.7.7"
4
+ gem "fastimage", "1.7.0"
5
+ gem "reddit_bot", "~>1.1.5"
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.8)
5
+ fastimage (1.7.0)
6
+ addressable (~> 2.3, >= 2.3.5)
7
+ json (1.8.3)
8
+ reddit_bot (1.1.5)
9
+ json
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ fastimage (= 1.7.0)
16
+ reddit_bot (~> 1.1.5)
17
+
18
+ BUNDLED WITH
19
+ 1.11.2
@@ -0,0 +1,34 @@
1
+ require_relative "../boilerplate"
2
+
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true#, subreddit: SUBREDDIT
4
+ SUBREDDIT = "wallpaper"
5
+
6
+ if ENV["LOGNAME"] == "nakilon"
7
+ require_relative "../../../../dimensioner/get_dimensions"
8
+ else
9
+ require_relative File.join Dir.home, "dimensioner/get_dimensions"
10
+ end
11
+
12
+ checked = []
13
+ loop do
14
+ AWSStatus::touch
15
+ puts "LOOP #{Time.now}"
16
+
17
+ # _ = DownloadWithRetry::download_with_retry("https://www.reddit.com/r/#{SUBREDDIT}.json?sort=new&restrict_sr=on&t=hour") \
18
+ BOT.json(:get, "/r/#{SUBREDDIT}/new")["data"]["children"].each do |post|
19
+ id, url, title, subreddit = post["data"].values_at(*%w{ id url title subreddit })
20
+ next if checked.include? id
21
+ checked.push id
22
+ next puts "skipped #{url} from http://redd.it/#{id}" if :skipped == _ = GetDimensions::get_dimensions(url)
23
+ next puts "unable #{url} from http://redd.it/#{id}" unless _
24
+ width, height, best_direct_url, *all_direct_urls = _
25
+
26
+ resolution = "#{width}x#{height}"
27
+ result = title[/\s*\[?#{width}\s*[*x×]\s*#{height}\]?\s*/i]
28
+ puts "#{!!result} #{id} [#{resolution}] #{title} #{url}"
29
+ BOT.report "true resolution is #{resolution}", "t3_#{id}" unless result
30
+ end
31
+
32
+ puts "END LOOP #{Time.now}"
33
+ sleep 60
34
+ end
data/lib/reddit_bot.rb CHANGED
@@ -8,7 +8,7 @@ require "json"
8
8
 
9
9
 
10
10
  module RedditBot
11
- VERSION = "1.1.5" # :nodoc:
11
+ VERSION = "1.1.6" # :nodoc:
12
12
 
13
13
  class Bot
14
14
 
@@ -229,8 +229,8 @@ module RedditBot
229
229
  end
230
230
  response = begin
231
231
  http.request request
232
- rescue Net::ReadTimeout, Errno::EPIPE, EOFError
233
- puts "ERROR: Net::ReadTimeout"
232
+ rescue Net::ReadTimeout, Errno::EPIPE, EOFError, SocketError, Zlib::BufError
233
+ puts "ERROR: network"
234
234
  retry
235
235
  end
236
236
  puts %w{
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.1.5
4
+ version: 1.1.6
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-04-30 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -36,12 +36,18 @@ files:
36
36
  - README.md
37
37
  - Rakefile
38
38
  - examples/boilerplate.rb
39
+ - examples/devflairbot/Gemfile
40
+ - examples/devflairbot/Gemfile.lock
41
+ - examples/devflairbot/main.rb
42
+ - examples/flairmotron/Gemfile
43
+ - examples/flairmotron/Gemfile.lock
44
+ - examples/flairmotron/main.rb
39
45
  - examples/iostroubleshooting/Gemfile
40
46
  - examples/iostroubleshooting/Gemfile.lock
41
47
  - examples/iostroubleshooting/main.rb
42
- - examples/largeimages/Gemfile
43
- - examples/largeimages/Gemfile.lock
44
- - examples/largeimages/main.rb
48
+ - examples/largeimagesreview/Gemfile
49
+ - examples/largeimagesreview/Gemfile.lock
50
+ - examples/largeimagesreview/main.rb
45
51
  - examples/mlgtv/Gemfile
46
52
  - examples/mlgtv/Gemfile.lock
47
53
  - examples/mlgtv/main.rb
@@ -51,6 +57,12 @@ files:
51
57
  - examples/pokemon_trading/Gemfile
52
58
  - examples/pokemon_trading/Gemfile.lock
53
59
  - examples/pokemon_trading/main.rb
60
+ - examples/sexypizza/Gemfile
61
+ - examples/sexypizza/Gemfile.lock
62
+ - examples/sexypizza/main.rb
63
+ - examples/wallpaper/Gemfile
64
+ - examples/wallpaper/Gemfile.lock
65
+ - examples/wallpaper/main.rb
54
66
  - examples/yayornay/Gemfile
55
67
  - examples/yayornay/Gemfile.lock
56
68
  - examples/yayornay/main.rb