From 321d77026318ec2be890968bed3b178d96db9557 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Mon, 11 Apr 2016 03:52:26 -0400 Subject: [PATCH] Initial commit --- .gitignore | 1 + Gemfile | 3 +++ Gemfile.lock | 16 ++++++++++++++++ serialboard.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 serialboard.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d3ed4c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.yml diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..2967b0e --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'pinboard' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..508c4ed --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,16 @@ +GEM + remote: https://rubygems.org/ + specs: + httparty (0.11.0) + multi_json (~> 1.0) + multi_xml (>= 0.5.2) + multi_json (1.11.2) + multi_xml (0.5.5) + pinboard (1.0.0) + httparty (= 0.11.0) + +PLATFORMS + ruby + +DEPENDENCIES + pinboard diff --git a/serialboard.rb b/serialboard.rb new file mode 100755 index 0000000..13be70d --- /dev/null +++ b/serialboard.rb @@ -0,0 +1,43 @@ +#!/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 + domain = post.href.sub(/^https?:\/\/(.*?)\/.*$/, "\\1") + + if !domains.include? domain + # Record that we've seen the domain now. + domains.push domain + else + 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."