reddit_bot 1.7.4 → 1.8.0
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/lib/reddit_bot.rb +63 -21
- data/reddit_bot.gemspec +9 -13
- metadata +12 -74
- 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/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 -107
- data/examples/largeimages/main.rb +0 -167
- 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/wallpaper/Gemfile +0 -5
- data/examples/wallpaper/Gemfile.lock +0 -33
- 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
- data/lib/reddit_bot/version.rb +0 -3
@@ -1 +0,0 @@
|
|
1
|
-
<body style="margin: 0"><iframe style="width: 100vw; height: 100vh" src="https://docs.google.com/spreadsheets/d/1CmO0cxd4z1_37Fvo4WpPdyTqmd_HmCF_nD6PgeHuCAA/pubhtml?gid=0&single=true&widget=false&headers=false&chrome=false"></iframe></body>
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative "../boilerplate"
|
2
|
-
BOT = RedditBot::Bot.new YAML.load_file "secrets.yaml"
|
3
|
-
|
4
|
-
require "gcplogger"
|
5
|
-
logger = GCPLogger.logger "cptflairbot3"
|
6
|
-
|
7
|
-
loop do
|
8
|
-
unread = BOT.json :get, "/message/unread"
|
9
|
-
unread["data"]["children"].each do |msg|
|
10
|
-
next logger.info "bad destination: #{msg["data"]["dest"]}" unless msg["data"]["dest"] == "CPTFlairBot3"
|
11
|
-
case msg["data"]["subject"]
|
12
|
-
when "casualpokemontrades"
|
13
|
-
unless /^(?<name>\S+( \S+)*) ?\n(?<id>\d\d\d\d-\d\d\d\d-\d\d\d\d)\n(?<css_class>[a-z2-]+)$/ =~ msg["data"]["body"]
|
14
|
-
logger.info "invalid message for #{msg["data"]["subject"]}: %p" % msg["data"]["body"] unless Google::Cloud.env.compute_engine?
|
15
|
-
# puts "marking invalid message as read: %p" % msg["data"]["body"]
|
16
|
-
# BOT.json :post, "/api/read_message", {id: msg["data"]["name"]} unless Gem::Platform.local.os == "darwin"
|
17
|
-
next
|
18
|
-
end
|
19
|
-
if name.size > 50
|
20
|
-
logger.info "too large name: %p" % name unless Google::Cloud.env.compute_engine?
|
21
|
-
next
|
22
|
-
end
|
23
|
-
begin
|
24
|
-
BOT.json :post, "/r/#{msg["data"]["subject"]}/api/flair", {
|
25
|
-
name: msg["data"]["author"],
|
26
|
-
text: {
|
27
|
-
"casualpokemontrades" => "#{id} | #{name}",
|
28
|
-
"relaxedpokemontrades" => "#{name} #{id}",
|
29
|
-
}[msg["data"]["subject"]],
|
30
|
-
css_class: css_class,
|
31
|
-
}.tap{ |h|
|
32
|
-
timeout = 0
|
33
|
-
begin
|
34
|
-
logger.warn h.merge( {
|
35
|
-
messaged_at: Time.at(msg["data"]["created_utc"]),
|
36
|
-
processed_at: Time.now,
|
37
|
-
} ), {
|
38
|
-
subreddit: msg["data"]["subject"],
|
39
|
-
}
|
40
|
-
rescue Google::Cloud::UnavailableError => e
|
41
|
-
logger.info "retrying in #{timeout += 1} seconds because of #{e}"
|
42
|
-
sleep timeout
|
43
|
-
retry
|
44
|
-
end
|
45
|
-
}
|
46
|
-
rescue RuntimeError => e
|
47
|
-
if e.to_s == "BAD_FLAIR_TARGET"
|
48
|
-
logger.error "#{e.to_s}: '#{msg["data"]["author"]}'"
|
49
|
-
else
|
50
|
-
raise e
|
51
|
-
end
|
52
|
-
end
|
53
|
-
BOT.json :post, "/api/read_message", {id: msg["data"]["name"]}
|
54
|
-
else
|
55
|
-
next logger.debug "bad subject: #{msg["data"]["subject"]}"
|
56
|
-
end
|
57
|
-
break # just for a case
|
58
|
-
end
|
59
|
-
|
60
|
-
logger.info "END LOOP #{Time.now}" unless Google::Cloud.env.compute_engine?
|
61
|
-
sleep 60
|
62
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# this emulates a Pub/Sub message from a 'casualpokemontrades' Sink for a deployed Function in Emulator as
|
2
|
-
# `GOOGLE_APPLICATION_CREDENTIALS="***.json" functions start`
|
3
|
-
# `functions deploy casualpokemontrades --trigger-topic casualpokemontrades`
|
4
|
-
# it waits for JSON payload from STDIN -- enter `{}` to use default payload sample
|
5
|
-
# after that you may wanna do `tail -30 /usr/local/lib/node_modules/@google-cloud/functions-emulator/logs/cloud-functions-emulator.log`
|
6
|
-
# to really deploy the Function do `gcloud beta functions deploy casualpokemontrades --stage-bucket casualpokemontrades.function.nakilon.pro --trigger-topic casualpokemontrades`
|
7
|
-
|
8
|
-
require "base64"
|
9
|
-
require "json"
|
10
|
-
|
11
|
-
base64 = Base64.strict_encode64 JSON.dump(
|
12
|
-
{
|
13
|
-
"insertId"=>"dbkwdqg109zgse",
|
14
|
-
"jsonPayload"=>{
|
15
|
-
"css_class"=>"charizard",
|
16
|
-
"messaged_at"=>"2017-08-19 10:11:57 +0300",
|
17
|
-
"name"=>"nakilon",
|
18
|
-
"processed_at"=>"2017-08-19 12:18:46 +0300",
|
19
|
-
"text"=>"0000-0000-0000 | test"
|
20
|
-
}.merge(JSON.load gets),
|
21
|
-
"labels"=>{"subreddit"=>"casualpokemontrades"},
|
22
|
-
"logName"=>"projects/nakilonpro/logs/cptflairbot3",
|
23
|
-
"receiveTimestamp"=>"2017-08-19T09:18:47.260056855Z",
|
24
|
-
"resource"=>{"labels"=>{"project_id"=>"nakilonpro"}, "type"=>"global"},
|
25
|
-
"severity"=>"WARNING",
|
26
|
-
"timestamp"=>"2017-08-19T09:18:46.666079Z"
|
27
|
-
}
|
28
|
-
)
|
29
|
-
|
30
|
-
exec 'functions call casualpokemontrades --data=\'{"data":"' + base64 + '","attributes":{"logging.googleapis.com/timestamp":"2017-08-19T09:18:46.666079Z"},"@type":"type.googleapis.com/google.pubsub.v1.PubsubMessage"}\''
|
@@ -1,74 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.5.2)
|
5
|
-
public_suffix (>= 2.0.2, < 4.0)
|
6
|
-
faraday (0.15.2)
|
7
|
-
multipart-post (>= 1.2, < 3)
|
8
|
-
google-cloud-core (1.2.1)
|
9
|
-
google-cloud-env (~> 1.0)
|
10
|
-
google-cloud-env (1.0.2)
|
11
|
-
faraday (~> 0.11)
|
12
|
-
google-cloud-error_reporting (0.27.0)
|
13
|
-
google-cloud-core (~> 1.0)
|
14
|
-
google-gax (~> 0.8.0)
|
15
|
-
stackdriver-core (~> 1.2)
|
16
|
-
google-gax (0.8.12)
|
17
|
-
google-protobuf (~> 3.2)
|
18
|
-
googleapis-common-protos (~> 1.3.5)
|
19
|
-
googleauth (~> 0.5.1)
|
20
|
-
grpc (~> 1.6.6)
|
21
|
-
rly (~> 0.2.3)
|
22
|
-
google-protobuf (3.6.0)
|
23
|
-
googleapis-common-protos (1.3.7)
|
24
|
-
google-protobuf (~> 3.0)
|
25
|
-
googleapis-common-protos-types (~> 1.0)
|
26
|
-
grpc (~> 1.0)
|
27
|
-
googleapis-common-protos-types (1.0.1)
|
28
|
-
google-protobuf (~> 3.0)
|
29
|
-
googleauth (0.5.3)
|
30
|
-
faraday (~> 0.12)
|
31
|
-
jwt (~> 1.4)
|
32
|
-
logging (~> 2.0)
|
33
|
-
memoist (~> 0.12)
|
34
|
-
multi_json (~> 1.11)
|
35
|
-
os (~> 0.9)
|
36
|
-
signet (~> 0.7)
|
37
|
-
grpc (1.6.7)
|
38
|
-
google-protobuf (~> 3.1)
|
39
|
-
googleapis-common-protos-types (~> 1.0.0)
|
40
|
-
googleauth (~> 0.5.1)
|
41
|
-
json (2.1.0)
|
42
|
-
jwt (1.5.6)
|
43
|
-
little-plugger (1.1.4)
|
44
|
-
logging (2.2.2)
|
45
|
-
little-plugger (~> 1.1)
|
46
|
-
multi_json (~> 1.10)
|
47
|
-
memoist (0.16.0)
|
48
|
-
multi_json (1.13.1)
|
49
|
-
multipart-post (2.0.0)
|
50
|
-
nethttputils (0.2.4.1)
|
51
|
-
os (0.9.6)
|
52
|
-
public_suffix (2.0.5)
|
53
|
-
reddit_bot (1.6.6)
|
54
|
-
json
|
55
|
-
nethttputils (~> 0.2.4.1)
|
56
|
-
rly (0.2.3)
|
57
|
-
signet (0.8.1)
|
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
|
-
google-cloud-error_reporting (~> 0.27.0)
|
70
|
-
public_suffix (< 3.0)
|
71
|
-
reddit_bot (~> 1.6.6)
|
72
|
-
|
73
|
-
BUNDLED WITH
|
74
|
-
1.16.1
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# The bot changes the post flair class with one with "dev" prefix
|
2
|
-
# if there is response from someone with "developer" user flair in comments.
|
3
|
-
# Seems like in current implementation it reads 10 last comments per subreddit
|
4
|
-
# so it's possible to miss if bot is down for a while but in fact it's enough stable and does not go down.
|
5
|
-
|
6
|
-
require_relative "../boilerplate"
|
7
|
-
BOT = RedditBot::Bot.new YAML.load_file "secrets.yaml"
|
8
|
-
|
9
|
-
fail("no ENV['ERROR_REPORTING_KEYFILE'] specified") unless ENV["ERROR_REPORTING_KEYFILE"]
|
10
|
-
require "google/cloud/error_reporting"
|
11
|
-
Google::Cloud::ErrorReporting.configure do |config|
|
12
|
-
config.project_id = (JSON.load File.read ENV["ERROR_REPORTING_KEYFILE"])["project_id"]
|
13
|
-
end
|
14
|
-
|
15
|
-
reported = []
|
16
|
-
loop do
|
17
|
-
puts "LOOP #{Time.now}"
|
18
|
-
|
19
|
-
moderated = BOT.json(:get, "/subreddits/mine/moderator")["data"]["children"].map do |child|
|
20
|
-
fail unless child["kind"] == "t5"
|
21
|
-
child["data"]["display_name"].downcase
|
22
|
-
end
|
23
|
-
[
|
24
|
-
# ["ion", "Developer"],
|
25
|
-
# ["survivetheculling", "Developer"],
|
26
|
-
["vigorgame", "Developer"],
|
27
|
-
["insurgency", "Developer"],
|
28
|
-
["Battalion1944", "Developer"],
|
29
|
-
].each do |subreddit, developer_class|
|
30
|
-
subreddit.downcase!
|
31
|
-
next puts "!!! can't moderate #{subreddit} !!!" unless moderated.include? subreddit
|
32
|
-
puts "sub: #{subreddit}"
|
33
|
-
|
34
|
-
JSON.parse( begin
|
35
|
-
NetHTTPUtils.request_data "https://www.reddit.com/r/#{subreddit}/comments.json", header: ["User-Agent", "ajsdjasdasd"]
|
36
|
-
rescue NetHTTPUtils::Error => e
|
37
|
-
raise unless [503, 504, 500].include? e.code
|
38
|
-
sleep 60
|
39
|
-
retry
|
40
|
-
end )["data"]["children"].each do |comment|
|
41
|
-
id = comment["data"]["link_id"][3..-1]
|
42
|
-
commenter_flair = comment["data"]["author_flair_css_class"]
|
43
|
-
puts "flair: #{commenter_flair}" if commenter_flair
|
44
|
-
next unless developer_class == commenter_flair
|
45
|
-
puts "https://reddit.com/r/#{subreddit}/comments/#{id}/#{comment["data"]["id"]} '#{commenter_flair}'"
|
46
|
-
flairselector = BOT.json :post, "/api/flairselector", { link: comment["data"]["link_id"] }
|
47
|
-
current_flair_class = flairselector["current"]["flair_css_class"]
|
48
|
-
puts "existing https://reddit.com/#{id} #{current_flair_class.inspect}"
|
49
|
-
next unless target = case current_flair_class
|
50
|
-
when nil then "untaggeddev"
|
51
|
-
when "news" then "newsdev"
|
52
|
-
when "discussion" then "discussiondev"
|
53
|
-
when "media" then "mediadev"
|
54
|
-
when "feedback" then "feedbackdev"
|
55
|
-
when "question" then "questiondev"
|
56
|
-
when "bug" then "bugdev"
|
57
|
-
when "announcement" then "announcementdev"
|
58
|
-
when "suggestion" then "suggestiondev"
|
59
|
-
else puts "ignored https://reddit.com/#{id} #{current_flair_class.inspect}"
|
60
|
-
end
|
61
|
-
unless choice = flairselector["choices"].find{ |choice| choice["flair_css_class"] == target }
|
62
|
-
next if reported.include? comment["data"]["link_id"]
|
63
|
-
Google::Cloud::ErrorReporting.report RuntimeError.new("no '#{target}' link flair in /r/#{subreddit}").tap{ |_| _.set_backtrace caller }
|
64
|
-
reported.push comment["data"]["link_id"]
|
65
|
-
next
|
66
|
-
end
|
67
|
-
puts "assigning '#{target}' (#{choice}) flair to post https://reddit.com/#{id}"
|
68
|
-
next if ENV["TEST"]
|
69
|
-
_ = BOT.json :post,
|
70
|
-
"/api/selectflair", {
|
71
|
-
flair_template_id: choice["flair_template_id"],
|
72
|
-
link: comment["data"]["link_id"],
|
73
|
-
}
|
74
|
-
fail _.inspect unless _ == {"json"=>{"errors"=>[]}}
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
puts "END LOOP #{Time.now}"
|
80
|
-
sleep 120
|
81
|
-
end
|
data/examples/get_dimensions.rb
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
# TODO deprecate in favor of the gem directlink
|
2
|
-
|
3
|
-
# TODO maybe activate raise_on_failure optional FastImage param
|
4
|
-
|
5
|
-
require "pp"
|
6
|
-
# require "json"
|
7
|
-
# require "nethttputils"
|
8
|
-
require "imgur2array"
|
9
|
-
require "fastimage"
|
10
|
-
|
11
|
-
module GetDimensions
|
12
|
-
class Error404 < RuntimeError
|
13
|
-
def initialize url
|
14
|
-
# Module.nesting[1].logger.error url
|
15
|
-
super "GetDimensions: NotFound error for #{url}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
class ErrorUnknown < RuntimeError
|
19
|
-
def initialize url
|
20
|
-
# Module.nesting[1].logger.error url
|
21
|
-
super "GetDimensions: fastimage can't get dimensions for unknown url #{url}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.get_dimensions url
|
26
|
-
fail "env var missing -- IMGUR_CLIENT_ID" unless ENV["IMGUR_CLIENT_ID"]
|
27
|
-
fail "env var missing -- FLICKR_API_KEY" unless ENV["FLICKR_API_KEY"]
|
28
|
-
fail "env var missing -- _500PX_CONSUMER_KEY" unless ENV["_500PX_CONSUMER_KEY"]
|
29
|
-
|
30
|
-
return :skipped if [
|
31
|
-
%r{^https://www\.youtube\.com/},
|
32
|
-
%r{^http://gfycat\.com/},
|
33
|
-
%r{^https?://(i\.)?imgur\.com/.+\.gifv$}, # TODO: o'rly?!
|
34
|
-
%r{^https?://www\.reddit\.com/},
|
35
|
-
%r{^http://vimeo\.com/},
|
36
|
-
].any?{ |r| r =~ url }
|
37
|
-
|
38
|
-
begin
|
39
|
-
URI url
|
40
|
-
rescue URI::InvalidURIError
|
41
|
-
return :skipped
|
42
|
-
end
|
43
|
-
# return :skipped if %w{ minus com } == .host.split(?.).last(2)
|
44
|
-
|
45
|
-
fi = lambda do |url|
|
46
|
-
_ = FastImage.size url
|
47
|
-
_ ? [*_, url] : fail
|
48
|
-
end
|
49
|
-
[
|
50
|
-
->_{
|
51
|
-
_ = FastImage.size url
|
52
|
-
[*_, url] if _
|
53
|
-
},
|
54
|
-
->_{ if %w{ imgur com } == URI(_).host.split(?.).last(2)
|
55
|
-
dimensions = begin
|
56
|
-
Imgur::imgur_to_array _
|
57
|
-
rescue Imgur::Error => e
|
58
|
-
raise Error404.new _ if e.to_s.start_with? "Imgur error: bad link pattern"
|
59
|
-
raise
|
60
|
-
end
|
61
|
-
raise Error404.new _ if !dimensions || dimensions.empty?
|
62
|
-
[
|
63
|
-
*dimensions.max_by{ |u, x, y, t| x * y }.take(3).rotate(1),
|
64
|
-
*dimensions.map(&:first),
|
65
|
-
]
|
66
|
-
end },
|
67
|
-
->_{ if %r{^https://www\.flickr\.com/photos/[^/]+/(?<id>[^/]+)} =~ _ ||
|
68
|
-
%r{^https://flic\.kr/p/(?<id>[^/]+)$} =~ _
|
69
|
-
json = JSON.parse NetHTTPUtils.request_data "https://api.flickr.com/services/rest/", form: {
|
70
|
-
method: "flickr.photos.getSizes",
|
71
|
-
api_key: ENV["FLICKR_API_KEY"],
|
72
|
-
photo_id: id,
|
73
|
-
format: "json",
|
74
|
-
nojsoncallback: 1,
|
75
|
-
}
|
76
|
-
raise Error404.new _ if json == {"stat"=>"fail", "code"=>1, "message"=>"Photo not found"}
|
77
|
-
if json["stat"] != "ok"
|
78
|
-
fail [json, _].inspect
|
79
|
-
else
|
80
|
-
json["sizes"]["size"].map do |_|
|
81
|
-
x, y, u = _.values_at("width", "height", "source")
|
82
|
-
[x.to_i, y.to_i, u]
|
83
|
-
end.max_by{ |x, y, u| x * y }
|
84
|
-
end
|
85
|
-
end },
|
86
|
-
->_{ if %r{https?://[^.]+.wiki[mp]edia\.org/wiki(/[^/]+)*/(?<id>File:.+)} =~ _
|
87
|
-
_ = JSON.parse NetHTTPUtils.request_data "https://commons.wikimedia.org/w/api.php", form: {
|
88
|
-
format: "json",
|
89
|
-
action: "query",
|
90
|
-
prop: "imageinfo",
|
91
|
-
iiprop: "url",
|
92
|
-
titles: id,
|
93
|
-
}
|
94
|
-
fi[_["query"]["pages"].values.first["imageinfo"].first["url"]]
|
95
|
-
end },
|
96
|
-
->_{ if %r{^https://500px\.com/photo/(?<id>[^/]+)/[^/]+$} =~ _
|
97
|
-
(JSON.parse NetHTTPUtils.request_data "https://api.500px.com/v1/photos/#{id}", form: {
|
98
|
-
image_size: 2048,
|
99
|
-
consumer_key: ENV["_500PX_CONSUMER_KEY"],
|
100
|
-
} )["photo"].values_at("width", "height", "image_url")
|
101
|
-
end },
|
102
|
-
->_{
|
103
|
-
raise Error404.new _ if "404" == begin
|
104
|
-
NetHTTPUtils.get_response _
|
105
|
-
rescue SocketError => e
|
106
|
-
raise Error404.new _
|
107
|
-
end.code
|
108
|
-
},
|
109
|
-
->_{ raise ErrorUnknown.new _ },
|
110
|
-
].lazy.map{ |_| _[url] }.find{ |_| _ }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
if $0 == __FILE__
|
115
|
-
STDOUT.sync = true
|
116
|
-
puts "self testing..."
|
117
|
-
|
118
|
-
[
|
119
|
-
["http://minus.com/lkP3hgRJd9npi", GetDimensions::Error404],
|
120
|
-
["http://example.com", GetDimensions::ErrorUnknown],
|
121
|
-
["http://i.imgur.com/7xcxxkR.gifv", :skipped],
|
122
|
-
["http://imgur.com/HQHBBBD", [1024, 768, "https://i.imgur.com/HQHBBBD.jpg",
|
123
|
-
"https://i.imgur.com/HQHBBBD.jpg"]],
|
124
|
-
["http://imgur.com/a/AdJUK", [1456, 2592, "https://i.imgur.com/Yunpxnx.jpg",
|
125
|
-
"https://i.imgur.com/Yunpxnx.jpg",
|
126
|
-
"https://i.imgur.com/3afw2aF.jpg",
|
127
|
-
"https://i.imgur.com/2epn2nT.jpg"]],
|
128
|
-
# TODO maybe we should do smth else with video -- maybe raise?
|
129
|
-
["https://imgur.com/9yaMdJq", [720, 404, "https://i.imgur.com/9yaMdJq.mp4",
|
130
|
-
"https://i.imgur.com/9yaMdJq.mp4"]],
|
131
|
-
["http://imgur.com/gallery/dCQprEq/new", [5760, 3840, "https://i.imgur.com/dCQprEq.jpg",
|
132
|
-
"https://i.imgur.com/dCQprEq.jpg"]],
|
133
|
-
["https://www.flickr.com/photos/tomas-/17220613278/", GetDimensions::Error404],
|
134
|
-
["https://www.flickr.com/photos/16936123@N07/18835195572", GetDimensions::Error404],
|
135
|
-
["https://www.flickr.com/photos/44133687@N00/17380073505/", [3000, 2000, "https://farm8.staticflickr.com/7757/17380073505_ed5178cc6a_o.jpg"]], # trailing slash
|
136
|
-
["https://www.flickr.com/photos/jacob_schmidt/18414267018/in/album-72157654235845651/", GetDimensions::Error404], # username in-album
|
137
|
-
["https://www.flickr.com/photos/tommygi/5291099420/in/dateposted-public/", [1600, 1062, "https://farm6.staticflickr.com/5249/5291099420_3bf8f43326_o.jpg"]], # username in-public
|
138
|
-
["https://www.flickr.com/photos/132249412@N02/18593786659/in/album-72157654521569061/", GetDimensions::Error404],
|
139
|
-
["https://www.flickr.com/photos/130019700@N03/18848891351/in/dateposted-public/", [4621, 3081, "https://farm4.staticflickr.com/3796/18848891351_f751b35aeb_o.jpg"]], # userid in-public
|
140
|
-
["https://www.flickr.com/photos/frank3/3778768209/in/photolist-6KVb92-eCDTCr-ur8K-7qbL5z-c71afh-c6YvXW-7mHG2L-c71ak9-c71aTq-c71azf-c71aq5-ur8Q-6F6YkR-eCDZsD-eCEakg-eCE6DK-4ymYku-7ubEt-51rUuc-buujQE-ur8x-9fuNu7-6uVeiK-qrmcC6-ur8D-eCEbei-eCDY9P-eCEhCk-eCE5a2-eCH457-eCHrcq-eCEdZ4-eCH6Sd-c71b5o-c71auE-eCHa8m-eCDSbz-eCH1dC-eCEg3v-7JZ4rh-9KwxYL-6KV9yR-9tUSbU-p4UKp7-eCHfwS-6KVbAH-5FrdbP-eeQ39v-eeQ1UR-4jHAGN", [1024, 681, "https://farm3.staticflickr.com/2499/3778768209_280f82abab_b.jpg"]],
|
141
|
-
["https://www.flickr.com/photos/patricksloan/18230541413/sizes/l", [2048, 491, "https://farm6.staticflickr.com/5572/18230541413_fec4783d79_k.jpg"]],
|
142
|
-
["https://flic.kr/p/vPvCWJ", [2048, 1365, "https://farm1.staticflickr.com/507/19572004110_d44d1b4ead_k.jpg"]],
|
143
|
-
["https://en.wikipedia.org/wiki/Prostitution_by_country#/media/File:Prostitution_laws_of_the_world.PNG", [1427, 628, "https://upload.wikimedia.org/wikipedia/commons/e/e8/Prostitution_laws_of_the_world.PNG"]],
|
144
|
-
["http://commons.wikimedia.org/wiki/File:Eduard_Bohlen_anagoria.jpg", [4367, 2928, "https://upload.wikimedia.org/wikipedia/commons/0/0d/Eduard_Bohlen_anagoria.jpg"]],
|
145
|
-
["https://500px.com/photo/112134597/milky-way-by-tom-hall", [4928, 2888, "https://drscdn.500px.org/photo/112134597/m%3D2048_k%3D1_a%3D1/v2?client_application_id=18857&webp=true&sig=c0d31cf9395d7849fbcce612ca9909225ec16fd293a7f460ea15d9e6a6c34257"]],
|
146
|
-
["https://i.redd.it/si758zk7r5xz.jpg", GetDimensions::Error404],
|
147
|
-
["http://www.cutehalloweencostumeideas.org/wp-content/uploads/2017/10/Niagara-Falls_04.jpg", GetDimensions::Error404],
|
148
|
-
["https://imgur.com/gallery/YO49F.", GetDimensions::Error404], # expect "Imgur error: bad link pattern"
|
149
|
-
["https://imgur.com/mM4Dh7Z", GetDimensions::Error404], # redirects to https://i.imgur.com/removed.png
|
150
|
-
].each do |input, expectation|
|
151
|
-
puts "testing #{input}"
|
152
|
-
if expectation.is_a? Class
|
153
|
-
begin
|
154
|
-
p GetDimensions::get_dimensions input
|
155
|
-
fail
|
156
|
-
rescue expectation
|
157
|
-
end
|
158
|
-
else
|
159
|
-
abort "unable to inspect #{input}" unless result = GetDimensions::get_dimensions(input)
|
160
|
-
abort "#{input} :: #{result.inspect} != #{expectation.inspect}" if result != expectation
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
puts "OK #{__FILE__}"
|
165
|
-
exit
|
166
|
-
end
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
__END__
|
174
|
-
|
175
|
-
["http://discobleach.com/wp-content/uploads/2015/06/spy-comic.png", []],
|
176
|
-
["http://spaceweathergallery.com/indiv_upload.php?upload_id=113462", []],
|
177
|
-
["http://livelymorgue.tumblr.com/post/121189724125/may-27-1956-in-an-eighth-floor-loft-of-an#notes", [0, 0]],
|
178
|
-
http://mobi900.deviantart.com/art/Sea-Sunrise-Wallpaper-545266270
|
179
|
-
http://mobi900.deviantart.com/art/Sunrise-Field-Wallpaper-545126742
|
180
|
-
|
181
|
-
|
182
|
-
http://boxtail.deviantart.com/art/Celtic-Water-Orbs-548986856 from http://redd.it/3en92j
|
183
|
-
http://imgur.com/OXCVSj7&k82U3Qj#0 from http://redd.it/3ee7j1
|
184
|
-
|
185
|
-
unable to size http://hubblesite.org/newscenter/archive/releases/2015/02/image/a/format/zoom/ from http://redd.it/2rhm8w
|
186
|
-
unable to size http://www.deviantart.com/art/Tree-swing-437944764 from http://redd.it/3fnia2
|
187
|
-
|
188
|
-
unable to size http://imgur.com/gallery/AsJ3N7x/new from http://redd.it/3fmzdg
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
found this to be already submitted
|
195
|
-
[4559, 2727] got from 3foerr: 'https://upload.wikimedia.org/wikipedia/commons/4/47/2009-09-19-helsinki-by-RalfR-062.jpg'
|
196
|
-
retry download 'https://www.reddit.com/r/LargeImages/search.json?q=url%3Ahttps%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F4%2F47%2F2009-09-19-helsinki-by-RalfR-062.jpg&restrict_sr=on' in 1 seconds because of 503 Service Unavailable
|
197
|
-
|
198
|
-
unable to size http://www.flickr.com/photos/dmacs_photos/12027867364/ from http://redd.it/1vqlgk
|
199
|
-
unable to size https://dl.dropboxusercontent.com/u/52357713/16k.png from http://redd.it/1vomwy
|
200
|
-
|
201
|
-
unable to size http://www.flickr.com/photos/dmacs_photos/12027867364/ from http://redd.it/1vqlgk
|
202
|
-
unable to size https://dl.dropboxusercontent.com/u/52357713/16k.png from http://redd.it/1vomwy
|
203
|
-
|
204
|
-
unable http://imgur.com/r/wallpaper/rZ37ZYN from http://redd.it/3knh3g
|
205
|
-
|
206
|
-
unable http://www.flickr.com/photos/dmacs_photos/12027867364/ from http://redd.it/1vqlgk
|
207
|
-
|
208
|
-
|
209
|
-
unable http://imgur.com/gallery/jm0OKQM from http://redd.it/3ukg4t
|
210
|
-
unable http://imgur.com/gallery/oZXfZ from http://redd.it/3ulz2i
|
211
|
-
|
212
|
-
|