serialboard/serialboard.rb

46 lines
1.2 KiB
Ruby
Executable File

#!/usr/bin/env ruby
#
# Use pinboard to keep your place in web serials.
require 'pinboard'
# Set up metrics
metric = {}
metric[:posts] = 0
metric[:posts_deleted] = 0
# Initialize the config
config = YAML.load_file('config.yml')
config['active_tag_name'] ||= 'serial'
config['deleted_tag_name'] ||= 'serial_deleted'
if config['api_token'].nil?
puts "Couldn't find API token. Please see the Configuration section of Readme.md."
return
end
# Get our data from the API
api = Pinboard.new(token: config['api_token'])
serial_posts = api.posts(tag: config['active_tag_name'])
serial_posts.sort! { |x,y| y.time <=> x.time }
domains = []
serial_posts.each do |post|
metric[:posts] += 1
# Extract the domain from the full URL
domain = post.href.sub(/^https?:\/\/(.*?)\/.*$/, "\\1")
if !domains.include? domain
# Record that we've seen the domain now.
domains.push domain
else
# If this is a duplicate, soft-delete it.
post.tag.delete config['active_tag_name']
post.tag.push config['deleted_tag_name']
post.shared = false
api.add post.api_hash(true)
metric[:posts_deleted] += 1
end
end
puts "#{metric[:posts]} posts found. #{metric[:posts_deleted]} posts deleted."