Add the ability to run serialboard on multiple accounts.
This commit is contained in:
parent
469212c74c
commit
1d5d9d39da
12
Readme.md
12
Readme.md
|
@ -12,6 +12,18 @@ First install ruby, then just:
|
||||||
|
|
||||||
Now copy config.yml.example to config.yml, and edit it to use your Pinboard API key.
|
Now copy config.yml.example to config.yml, and edit it to use your Pinboard API key.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Copy the `config.yml.example` to `config.yml` and edit it to use your API token. You can add additional tokens to process multiple accounts as well, e.g.:
|
||||||
|
|
||||||
|
```
|
||||||
|
- api_token: api_token_2
|
||||||
|
active_tag_name: comics
|
||||||
|
deleted_tag_name: archived
|
||||||
|
- api_token: api_token_3
|
||||||
|
```
|
||||||
|
|
||||||
|
`active_tag_name` and `deleted_tag_name` are optional, and will default to 'serial' and 'serial_deleted', respectively.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
api_token: replace_with_your_api_token
|
- api_token: replace_with_your_api_token
|
||||||
active_tag_name: serial
|
active_tag_name: serial
|
||||||
deleted_tag_name: serial_deleted
|
deleted_tag_name: serial_deleted
|
||||||
|
|
|
@ -4,23 +4,32 @@
|
||||||
|
|
||||||
require 'pinboard'
|
require 'pinboard'
|
||||||
|
|
||||||
|
# Initialize the config.
|
||||||
|
config = YAML.load_file('config.yml')
|
||||||
|
|
||||||
|
users = []
|
||||||
|
config.each do |user_config|
|
||||||
|
user = {}
|
||||||
|
user['active'] = user_config['active_tag_name'] ||= 'serial'
|
||||||
|
user['deleted'] = user_config['deleted_tag_name'] ||= 'serial_deleted'
|
||||||
|
|
||||||
|
if user_config['api_token'].nil?
|
||||||
|
puts "Couldn't find API token. Skipping user. Please see the Configuration section of Readme.md."
|
||||||
|
else
|
||||||
|
user['token'] = user_config['api_token']
|
||||||
|
users << user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
users.each do |user|
|
||||||
# Set up metrics
|
# Set up metrics
|
||||||
metric = {}
|
metric = {}
|
||||||
metric[:posts] = 0
|
metric[:posts] = 0
|
||||||
metric[:posts_deleted] = 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
|
# Get our data from the API
|
||||||
api = Pinboard.new(token: config['api_token'])
|
api = Pinboard.new(token: user['token'])
|
||||||
serial_posts = api.posts(tag: config['active_tag_name'])
|
serial_posts = api.posts(tag: user['active'])
|
||||||
serial_posts.sort! { |x,y| y.time <=> x.time }
|
serial_posts.sort! { |x,y| y.time <=> x.time }
|
||||||
|
|
||||||
domains = []
|
domains = []
|
||||||
|
@ -34,8 +43,8 @@ serial_posts.each do |post|
|
||||||
domains.push domain
|
domains.push domain
|
||||||
else
|
else
|
||||||
# If this is a duplicate, soft-delete it.
|
# If this is a duplicate, soft-delete it.
|
||||||
post.tag.delete config['active_tag_name']
|
post.tag.delete user['active']
|
||||||
post.tag.push config['deleted_tag_name']
|
post.tag.push user['deleted']
|
||||||
post.shared = false
|
post.shared = false
|
||||||
api.add post.api_hash(true)
|
api.add post.api_hash(true)
|
||||||
metric[:posts_deleted] += 1
|
metric[:posts_deleted] += 1
|
||||||
|
@ -43,3 +52,4 @@ serial_posts.each do |post|
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "#{metric[:posts]} posts found. #{metric[:posts_deleted]} posts deleted."
|
puts "#{metric[:posts]} posts found. #{metric[:posts_deleted]} posts deleted."
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user