Skip to content

Commit

Permalink
Add reddit.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Aug 27, 2020
1 parent 3076ca2 commit df3dc09
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions reddit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env ruby

require 'redd'
require 'aws-sdk-rekognition'
require 'open-uri'
require 'json'


session = Redd.it(
user_agent: 'Redd:FindMyAncestor:v1.0.0 (by /u/Mustermind)',
client_id: ENV['REDDIT_CLIENT_ID'],
secret: ENV['REDDIT_SECRET'],
username: ENV['REDDIT_LOGIN'],
password: ENV['REDDIT_PASSWORD'],
)

rekognition = Aws::Rekognition::Client.new(
region: 'eu-west-1',
profile: 'perso',
)

subreddit = ARGV[0] || 'TheWayWeWere'
page = 1
imported = 0

listing = session.subreddit(subreddit).listing(:top)
listing.each_with_index do |l, i|
url = l.url
uri = URI.parse(url)
id = l.id
img = uri.path.sub(%r{^/}, '')
ref = "reddit:#{subreddit}:#{id}:#{img}"

begin
img = open(url)
puts "[#{imported+i+1}] Importing #{ref} (#{url}) into collection"
rekognition.index_faces({
collection_id: 'flickr',
image: { bytes: img.read },
external_image_id: ref,
})
rescue => e
puts "W: failed to import #{ref} (#{url}): #{e}"
end
end

page += 1
imported += listing.length

puts "imported #{imported} photos"

0 comments on commit df3dc09

Please sign in to comment.