reddit_bot 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 305bb60aab77793751a1ebd2a999dfc657cb7dfe
4
- data.tar.gz: 6ca3d8ebf4d31cb980ab6694034a7b2d85197cc0
3
+ metadata.gz: 12c8ad9df61dbafab56150f521ff9714560d2146
4
+ data.tar.gz: 50d1d6f7343d404c0e1febd18021d243ada03672
5
5
  SHA512:
6
- metadata.gz: 6a02edccecbdb082ac0ef432d4402564931f47ff08c1c472e8370660f492e5fefab1c4eead7c5c3ff758342adaf738d6b394a50a231fa83e07eb3bbb12d0f3ec
7
- data.tar.gz: 0fd8bbb254327df02bc65b0c2cf77cbefd4280b66542a8c4f35771ab273c0ae657b41ffe811732fb22f6d198eeb2be8c6afec40dcc049c6f1a438fa95929fb0a
6
+ metadata.gz: 18c4d2ed6b45682d2ecca5bdb3d7111b5db74108a1b71d6ba4ee8ef4f5fd43ffb26838799c590904f465b35306f26cad234c22f143f42a3d18b9106987323943
7
+ data.tar.gz: aad031f0c1b1f847d363b5290069472db371976ffa1e89b56b5ce085ca497a070dc0eb53d1f479ceb0676a0ac9b876fe5199e756fbf26ba8126a52303260913d
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  #### What
8
8
 
9
9
  This library provides an easy way to run bots and scripts that use Reddit API.
10
- I (@nakilon) currently run 8 bots with it.
10
+ I (@nakilon) currently run near 10 bots with it.
11
11
 
12
12
  #### Why
13
13
 
@@ -33,23 +33,13 @@ The [examples folder](examples) includes:
33
33
  SkyPorn Total: 11 Quality: 45%
34
34
  carporn Total: 11 Quality: 45%
35
35
  InfrastructurePorn Total: 9 Quality: 77%
36
- ArtPorn Total: 9 Quality: 22%
37
- EarthPorn Total: 8 Quality: 75%
38
- waterporn Total: 8 Quality: 87%
39
- GunPorn Total: 7 Quality: 85%
40
- ExposurePorn Total: 7 Quality: 57%
41
- DessertPorn Total: 7 Quality: 14%
42
- MilitaryPorn Total: 7 Quality: 57%
43
- ArchitecturePorn Total: 7 Quality: 57%
44
- spaceporn Total: 7 Quality: 14%
45
- AbandonedPorn Total: 6 Quality: 50%
46
36
 
47
- You obviously can't run these examples as is, because they have some dependencies that are not in this repo. Like `secrets` file for authorization of the following format:
37
+ You obviously can't run these examples as is, because they have some dependencies that are not in this repo. Like `secrets.yaml` file for authorization of the following format:
48
38
 
49
- Kb9.......6wBw
50
- Fqo.....................AFI
51
- mybotpassword
52
- MyBotUsername
39
+ :client_id: Kb9.......6wBw
40
+ :client_secret: Fqo.....................AFI
41
+ :password: mybotpassword
42
+ :login: MyBotUsername
53
43
 
54
44
  #### Usage
55
45
 
@@ -1,4 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # gem "json"
4
- gem "reddit_bot"
3
+ gem "reddit_bot", "~>1.0"
@@ -1,7 +1,9 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- reddit_bot (0.1.0)
4
+ json (1.8.3)
5
+ reddit_bot (1.0.0)
6
+ json
5
7
 
6
8
  PLATFORMS
7
9
  ruby
@@ -1,7 +1,8 @@
1
1
  require_relative File.join "..", "boilerplate"
2
2
 
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
4
+
3
5
  SUBREDDIT = "codcompetitive"
4
- # SUBREDDIT = "test___________"
5
6
 
6
7
  loop do
7
8
  AWSStatus::touch
@@ -47,7 +48,7 @@ loop do
47
48
 
48
49
  end.join(" \n") + "\n"
49
50
 
50
- settings = RedditBot.json(:get, "/r/#{SUBREDDIT}/about/edit")["data"]
51
+ settings = BOT.json(:get, "/r/#{SUBREDDIT}/about/edit")["data"]
51
52
  # https://github.com/praw-dev/praw/blob/c45e5f6ca0c5cd9968b51301989eb82740f8dc85/praw/__init__.py#L1592
52
53
  settings.store "sr", settings.delete("subreddit_id")
53
54
  settings.store "lang", settings.delete("language")
@@ -68,7 +69,7 @@ loop do
68
69
  next puts "nothing to change" if prefix + text + postfix == settings["description"]
69
70
 
70
71
  settings["description"] = prefix + text + postfix
71
- _ = RedditBot.json :post, "/api/site_admin", settings.to_a
72
+ _ = BOT.json :post, "/api/site_admin", settings.to_a
72
73
  fail _.inspect if _ != {"json"=>{"errors"=>[]}} && !(_["json"]["errors"].map(&:first) - ["BAD_CAPTCHA"]).empty?
73
74
 
74
75
  end
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
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
8
+
9
+ gem "fastimage", "1.7.0"
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ reddit_bot (1.0.1)
5
+ json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ fastimage (1.7.0)
12
+ addressable (~> 2.3, >= 2.3.5)
13
+ json (1.8.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ fastimage (= 1.7.0)
20
+ reddit_bot (~> 1.0)!
21
+
22
+ BUNDLED WITH
23
+ 1.11.2
@@ -0,0 +1,39 @@
1
+ require_relative "../boilerplate"
2
+
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
4
+
5
+ require_relative "../../../../dimensioner/get_dimensions"
6
+
7
+ SUBREDDIT = "test___________"
8
+ FLAIR_CLASS = "redflair"
9
+
10
+ checked = []
11
+ loop do
12
+ AWSStatus::touch
13
+ puts "LOOP #{Time.now}"
14
+
15
+ _ = DownloadWithRetry::download_with_retry("https://www.reddit.com/r/#{SUBREDDIT}.json?sort=new&restrict_sr=on&t=hour") and
16
+ JSON.parse(_)["data"]["children"].each do |item|
17
+ id, url, title, subreddit = item["data"].values_at(*%w{ id url title subreddit })
18
+ next if checked.include? id # WTF?
19
+ checked << id
20
+ next puts "skipped #{url} from https://redd.it/#{id}" if :skipped == _ = GetDimensions::get_dimensions(url)
21
+ next puts "unable #{url} from https://redd.it/#{id}" unless _
22
+ width, height, * = _
23
+ result = ([1080, 1920] != resolution = [width, height])
24
+ puts "#{result} #{id} [#{resolution}] #{title} #{url}"
25
+ next if result
26
+ {"json"=>{"errors"=>[]}} == _ = BOT.json(:post,
27
+ "/api/selectflair",
28
+ flair_template_id: BOT.json(:post,
29
+ "/api/flairselector",
30
+ link: "t3_#{id}",
31
+ )["choices"].find{ |i| i["flair_css_class"] == FLAIR_CLASS }["flair_template_id"],
32
+ link: "t3_#{id}",
33
+ ) or fail _.inspect
34
+ BOT.report "1080x1920", "t3_#{id}"
35
+ end or puts "/r/#{SUBREDDIT} seems to be 403-ed"
36
+
37
+ puts "END LOOP #{Time.now}"
38
+ sleep 300
39
+ end
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
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
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ reddit_bot (1.0.0)
5
+ json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ json (1.8.3)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ reddit_bot (~> 1.0)!
17
+
18
+ BUNDLED WITH
19
+ 1.11.2
@@ -0,0 +1,45 @@
1
+ require_relative File.join "..", "boilerplate"
2
+
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets"), ignore_captcha: true
4
+
5
+ loop do
6
+ AWSStatus::touch
7
+
8
+ unread = BOT.json :get, "/message/unread"
9
+ unread["data"]["children"].each do |msg|
10
+ # next unless msg["data"]["author"] == "nakilon" if ENV["LOGNAME"] == "nakilon"
11
+ next puts "bad destination: #{msg["data"]["dest"]}" unless msg["data"]["dest"] == "CPTFlairBot3"
12
+ case msg["data"]["subject"]
13
+ when "casualpokemontrades", "relaxedpokemontrades"
14
+ unless /^(?<name>\S+)\n(?<id>\d\d\d\d-\d\d\d\d-\d\d\d\d)\n(?<css_class>\S+)$/ =~ msg["data"]["body"]
15
+ puts "invalid message for #{msg["data"]["subject"]}: %p" % msg["data"]["body"] if ENV["LOGNAME"] == "nakilon"
16
+ # puts "marking invalid message as read: %p" % msg["data"]["body"]
17
+ # BOT.json :post, "/api/read_message", {id: msg["data"]["name"]} unless ENV["LOGNAME"] == "nakilon"
18
+ next
19
+ end
20
+ begin
21
+ BOT.json :post, "/r/#{msg["data"]["subject"]}/api/flair", {
22
+ name: msg["data"]["author"],
23
+ text: {
24
+ "casualpokemontrades" => "#{id} | #{name}",
25
+ "relaxedpokemontrades" => "#{name} #{id}",
26
+ }[msg["data"]["subject"]],
27
+ css_class: css_class,
28
+ }.tap{ |h| puts "setting up flair at /r/#{msg["data"]["subject"]}: #{h}" }
29
+ rescue RuntimeError => e
30
+ if e.to_s == "BAD_FLAIR_TARGET"
31
+ puts "#{e.to_s}: '#{msg["data"]["author"]}'"
32
+ else
33
+ raise e
34
+ end
35
+ end
36
+ BOT.json :post, "/api/read_message", {id: msg["data"]["name"]}
37
+ else
38
+ next puts "bad subject: #{msg["data"]["subject"]}"
39
+ end
40
+ break # just for a case
41
+ end
42
+
43
+ puts "END LOOP #{Time.now}" if ENV["LOGNAME"] == "nakilon"
44
+ sleep 60
45
+ end
data/lib/reddit_bot.rb CHANGED
@@ -8,7 +8,7 @@ require "json"
8
8
 
9
9
 
10
10
  module RedditBot
11
- VERSION = "1.0.0"
11
+ VERSION = "1.0.1"
12
12
 
13
13
  class Bot
14
14
 
@@ -53,6 +53,13 @@ module RedditBot
53
53
  # ["previous", result["data"]["children"].last["id"]],
54
54
  end
55
55
 
56
+ def report reason, thing_id
57
+ json :post, "/api/report",
58
+ reason: "other",
59
+ other_reason: reason,
60
+ thing_id: thing_id
61
+ end
62
+
56
63
  private
57
64
 
58
65
  def token
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.0.0
4
+ version: 1.0.1
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-02-10 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -45,6 +45,12 @@ files:
45
45
  - examples/mlgtv/Gemfile
46
46
  - examples/mlgtv/Gemfile.lock
47
47
  - examples/mlgtv/main.rb
48
+ - examples/oneplus/Gemfile
49
+ - examples/oneplus/Gemfile.lock
50
+ - examples/oneplus/main.rb
51
+ - examples/pokemon_trading/Gemfile
52
+ - examples/pokemon_trading/Gemfile.lock
53
+ - examples/pokemon_trading/main.rb
48
54
  - lib/reddit_bot.rb
49
55
  - reddit_bot.gemspec
50
56
  homepage: https://github.com/Nakilon/reddit_bot