unsavory 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +27 -7
- data/bin/unsavory +17 -8
- data/lib/pinboard_client.rb +3 -2
- data/lib/utilities.rb +35 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc56464c97a4ee80fe1c35e371a103a90de10bc9
|
4
|
+
data.tar.gz: 42ddd718d418035adbdbd6b55e73e10ef370847e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28919e21cf5030872d78a7ff8267d806b9c28c6d0db6d70f63fa8e0a80c88173407515c74b5ed4e102860ae67a0d03b6ff7e8fbd428bfbed2c8935831c7568f8
|
7
|
+
data.tar.gz: 11ddf8eaac111e52cf972fcef1d280e8170c0d0ebb36037da42d583c2baaa62b274224ca13bd4c9fd28693a9d5004f348cefae4ba892b15da163bcc92a1f79c9
|
data/README.rdoc
CHANGED
@@ -2,13 +2,29 @@
|
|
2
2
|
|
3
3
|
unsavory is a little Ruby script which checks your Pinboard bookmarks for dead links (ENOENT or HTTP status code 404) and removes them. Additionally it will also inform you about links which return a status code other than 200 (OK).
|
4
4
|
|
5
|
-
==
|
6
|
-
|
7
|
-
After installing unsavory with
|
5
|
+
== Installation
|
8
6
|
|
9
7
|
$ gem install unsavory
|
10
8
|
|
11
|
-
|
9
|
+
== Options
|
10
|
+
|
11
|
+
unsavory [OPTIONS]
|
12
|
+
|
13
|
+
-h, --help:
|
14
|
+
show help
|
15
|
+
|
16
|
+
-d, --dry-run:
|
17
|
+
only log outdated links without deleting them
|
18
|
+
|
19
|
+
-p, --http-proxy:
|
20
|
+
specify an HTTP proxy (e.g. --http-proxy="http://webproxy:8080")
|
21
|
+
|
22
|
+
-l, --log-file:
|
23
|
+
location of the log file (default: ./unsavory.log)
|
24
|
+
|
25
|
+
== Usage
|
26
|
+
|
27
|
+
You can start the program from the command-line like this:
|
12
28
|
|
13
29
|
$ unsavory
|
14
30
|
|
@@ -18,15 +34,17 @@ It will first check if it can find the configuration file '~/.unsavory', which s
|
|
18
34
|
|
19
35
|
In case this file doesn't exist, HighLine will be used to prompt for login credentials. If this gem isn't available, the script will display an error message and abort.
|
20
36
|
|
21
|
-
|
37
|
+
While running unsavory will display a progressbar and an estimated time until completion:
|
22
38
|
|
23
39
|
Enter Pinboard username: citizen428
|
24
40
|
Enter Pinboard password: *************
|
25
41
|
|
26
42
|
citizen428 has 774 bookmarks.
|
27
|
-
|
43
|
+
Checking: 3% |o | ETA: 00:09:34
|
44
|
+
|
45
|
+
It will also create a logfile which contains information on deleted URLs, as well as redirects and all HTTP response codes other than 200 (OK).
|
28
46
|
|
29
|
-
|
47
|
+
If you don't want to actually delete links, please use the '--dry-run' option (also available as '-n').
|
30
48
|
|
31
49
|
== Warning
|
32
50
|
|
@@ -37,10 +55,12 @@ Any link that returns an HTTP status code of 404 will be deleted without warning
|
|
37
55
|
# Write tests.
|
38
56
|
# Use tests to clean up code.
|
39
57
|
# Add option to replace links with Archive.org links
|
58
|
+
# Add option to update redirects
|
40
59
|
|
41
60
|
== Thanks
|
42
61
|
|
43
62
|
# thelibrarian[https://github.com/thelibrarian]: for implementing HTTPS support and the '--dry-run' option
|
63
|
+
# thomd[https://github.com/thomd]: for adding proxy support
|
44
64
|
|
45
65
|
== Author
|
46
66
|
|
data/bin/unsavory
CHANGED
@@ -9,8 +9,13 @@ require_relative "../lib/pinboard_client.rb"
|
|
9
9
|
require_relative "../lib/utilities.rb"
|
10
10
|
|
11
11
|
opts = Utilities.get_options
|
12
|
-
pinboard_client = PinboardClient.new(opts
|
13
|
-
|
12
|
+
pinboard_client = PinboardClient.new(opts)
|
13
|
+
# if the first arg is nil, Net::HTTP:Proxy returns a Net::HTTP object
|
14
|
+
http_client = Net::HTTP::Proxy(*opts.values_at(:proxy_host,
|
15
|
+
:proxy_port,
|
16
|
+
:proxy_user,
|
17
|
+
:proxy_pass))
|
18
|
+
logger = Logger.new(opts[:logfile])
|
14
19
|
|
15
20
|
logger.info "Unsavory started: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
|
16
21
|
|
@@ -21,12 +26,15 @@ unless urls
|
|
21
26
|
exit 1
|
22
27
|
end
|
23
28
|
puts "\n#{opts[:user]} has #{urls.length} bookmarks."
|
24
|
-
puts "You are using dry run mode. No links will be deleted!\n\n" if opts[:dry_run]
|
25
29
|
|
26
|
-
|
30
|
+
if opts[:dry_run]
|
31
|
+
puts "You are using dry run mode. No links will be deleted!\n\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
pbar = ProgressBar.new("Checking", urls.size)
|
27
35
|
moved = 0
|
28
36
|
|
29
|
-
urls.
|
37
|
+
urls.each do |url|
|
30
38
|
pbar.inc
|
31
39
|
delete = false
|
32
40
|
use_ssl = false
|
@@ -38,10 +46,9 @@ urls.each_with_index do |url, idx|
|
|
38
46
|
end
|
39
47
|
|
40
48
|
begin
|
41
|
-
|
49
|
+
http_client.start(uri.host, uri.port, :use_ssl => use_ssl) do |http|
|
42
50
|
response = http.head(uri.path.empty? ? '/' : uri.path)
|
43
51
|
|
44
|
-
# handle redirects
|
45
52
|
if response.is_a?(Net::HTTPRedirection)
|
46
53
|
moved += 1
|
47
54
|
logger.info "#{url} redirects to #{response['location']}"
|
@@ -74,4 +81,6 @@ end
|
|
74
81
|
pbar.finish
|
75
82
|
logger.close
|
76
83
|
|
77
|
-
|
84
|
+
if moved > 0
|
85
|
+
puts "\n#{moved} URIs are redirecting to new locations, you might want to fix them."
|
86
|
+
end
|
data/lib/pinboard_client.rb
CHANGED
@@ -5,8 +5,9 @@ class PinboardClient
|
|
5
5
|
base_uri 'https://api.pinboard.in/v1/'
|
6
6
|
headers "User-Agent" => "Unsavory"
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@options = {:basic_auth => {:username => user, :password =>
|
8
|
+
def initialize(opts)
|
9
|
+
@options = {:basic_auth => {:username => opts[:user], :password => opts[:pass]}}
|
10
|
+
self.class.http_proxy(*opts.values_at(:proxy_host, :proxy_port, :proxy_user, :proxy_pass))
|
10
11
|
end
|
11
12
|
|
12
13
|
def get_urls
|
data/lib/utilities.rb
CHANGED
@@ -2,7 +2,8 @@ require 'getoptlong'
|
|
2
2
|
|
3
3
|
module Utilities
|
4
4
|
class << self
|
5
|
-
|
5
|
+
PROGRAM_NAME = File.basename($0)
|
6
|
+
CFG_FILE = File.join(ENV['HOME'], ".#{PROGRAM_NAME}")
|
6
7
|
|
7
8
|
def get_options
|
8
9
|
get_credentials.merge(parse_options)
|
@@ -11,7 +12,6 @@ module Utilities
|
|
11
12
|
private
|
12
13
|
def get_credentials
|
13
14
|
if File.exists?(CFG_FILE)
|
14
|
-
puts "Using config file '#{CFG_FILE}'"
|
15
15
|
user, pass = File.new(CFG_FILE).gets.chomp.split(':', 2)
|
16
16
|
else
|
17
17
|
begin
|
@@ -29,12 +29,43 @@ module Utilities
|
|
29
29
|
|
30
30
|
def parse_options
|
31
31
|
options = {}
|
32
|
-
opts = GetoptLong.new(
|
32
|
+
opts = GetoptLong.new(
|
33
|
+
['--dry-run', '-n', GetoptLong::NO_ARGUMENT],
|
34
|
+
['--http-proxy', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
35
|
+
['--log-file', '-l', GetoptLong::REQUIRED_ARGUMENT],
|
36
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT]
|
37
|
+
)
|
33
38
|
|
34
|
-
opts.each do |opt,
|
39
|
+
opts.each do |opt, arg|
|
35
40
|
case opt
|
41
|
+
when '--help'
|
42
|
+
puts <<EOF
|
43
|
+
#{PROGRAM_NAME} [OPTIONS]
|
44
|
+
|
45
|
+
-h, --help:
|
46
|
+
show help
|
47
|
+
|
48
|
+
-d, --dry-run:
|
49
|
+
only log outdated links without deleting them
|
50
|
+
|
51
|
+
-p, --http-proxy:
|
52
|
+
specify an HTTP proxy (e.g. --http-proxy="http://webproxy:8080")
|
53
|
+
|
54
|
+
-l, --log-file:
|
55
|
+
location of the log file (default: ./unsavory.log)
|
56
|
+
EOF
|
57
|
+
exit 0
|
36
58
|
when '--dry-run'
|
37
59
|
options[:dry_run] = true
|
60
|
+
when '--http-proxy'
|
61
|
+
options[:http_proxy] = true
|
62
|
+
uri = URI.parse(arg)
|
63
|
+
options[:proxy_host] = uri.host
|
64
|
+
options[:proxy_port] = uri.port || 8080
|
65
|
+
options[:proxy_user] = uri.user
|
66
|
+
options[:proxy_pass] = uri.password
|
67
|
+
when '--log-file'
|
68
|
+
options[:logfile] = File.expand_path(arg)
|
38
69
|
end
|
39
70
|
end
|
40
71
|
options
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unsavory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Kohl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|