unsavory 0.3.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +13 -21
- data/bin/unsavory +15 -10
- metadata +19 -4
data/README.rdoc
CHANGED
|
@@ -6,43 +6,35 @@ unsavory is a little Ruby script which checks your Pinboard bookmarks for dead l
|
|
|
6
6
|
|
|
7
7
|
After installing unsavory with
|
|
8
8
|
|
|
9
|
-
$ gem install
|
|
9
|
+
$ gem install unsavory
|
|
10
10
|
|
|
11
11
|
you can start it from the command-line like this:
|
|
12
12
|
|
|
13
13
|
$ unsavory
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
It will first check if it can find the configuration file '~/.unsavory', which should have the following format:
|
|
16
16
|
|
|
17
17
|
user:password
|
|
18
18
|
|
|
19
19
|
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
20
|
|
|
21
|
-
When run, unsavory will generate
|
|
22
|
-
|
|
23
|
-
Enter Pinboard username:
|
|
24
|
-
Enter Pinboard password:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Processing URL #0004: OK
|
|
31
|
-
Processing URL #0005: OK
|
|
32
|
-
...
|
|
33
|
-
Processing URL #0013: 405: http://...
|
|
34
|
-
...
|
|
35
|
-
Processing URL #0074: 302: http://...
|
|
36
|
-
...
|
|
37
|
-
Processing URL #0086: Connection reset by peer - https://...
|
|
21
|
+
When run, unsavory will generate display a progressbar and an estimate time until completion:
|
|
22
|
+
|
|
23
|
+
Enter Pinboard username: citizen428
|
|
24
|
+
Enter Pinboard password: *************
|
|
25
|
+
|
|
26
|
+
citizen428 has 774 bookmarks.
|
|
27
|
+
URLs: 3% |o | ETA: 00:09:34
|
|
28
|
+
|
|
29
|
+
It will also create a logfile name 'unsavory.log' in the directory where it was started. The log contains information on deleted URLs, as well as redirects and all HTTP response codes other than 200 (OK).
|
|
38
30
|
|
|
39
31
|
== Warning
|
|
40
32
|
|
|
41
|
-
Any link that returns an HTTP status code of 404 will be deleted without warning
|
|
33
|
+
Any link that returns an HTTP status code of 404 will be deleted without warning. There's no undo, use at your own risk!
|
|
42
34
|
|
|
43
35
|
== Todo
|
|
44
36
|
|
|
45
|
-
# None
|
|
37
|
+
# None at the moment.
|
|
46
38
|
|
|
47
39
|
== Author
|
|
48
40
|
|
data/bin/unsavory
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Copyright (c) 2009 Michael Kohl
|
|
3
3
|
|
|
4
4
|
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
|
5
|
-
%w{rubygems net/http pinboard}.each { |x| require x }
|
|
5
|
+
%w{rubygems net/http pinboard logger progressbar}.each { |x| require x }
|
|
6
6
|
highline = true
|
|
7
7
|
begin
|
|
8
8
|
require 'highline'
|
|
@@ -27,6 +27,8 @@ else
|
|
|
27
27
|
exit 1
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
logger = Logger.new('unsavory.log')
|
|
31
|
+
logger.info "Unsavory started: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
|
|
30
32
|
pinboard = Pinboard.new(user, pass)
|
|
31
33
|
moved = 0
|
|
32
34
|
|
|
@@ -44,8 +46,10 @@ end
|
|
|
44
46
|
|
|
45
47
|
puts "\n#{user} has #{urls.length} bookmarks."
|
|
46
48
|
|
|
49
|
+
pbar = ProgressBar.new("URLs", urls.size)
|
|
50
|
+
|
|
47
51
|
urls.each_with_index do |url, idx|
|
|
48
|
-
|
|
52
|
+
pbar.inc
|
|
49
53
|
uri = URI.parse(url)
|
|
50
54
|
response = nil
|
|
51
55
|
|
|
@@ -54,7 +58,7 @@ urls.each_with_index do |url, idx|
|
|
|
54
58
|
response = http.head(uri.path.size > 0 ? uri.path : "/")
|
|
55
59
|
end
|
|
56
60
|
rescue => e
|
|
57
|
-
|
|
61
|
+
logger.error "#{e.message} - #{url}"
|
|
58
62
|
next
|
|
59
63
|
end
|
|
60
64
|
|
|
@@ -62,16 +66,17 @@ urls.each_with_index do |url, idx|
|
|
|
62
66
|
if response.is_a?(Net::HTTPRedirection)
|
|
63
67
|
new_uri = URI.parse(response['location'])
|
|
64
68
|
moved += 1
|
|
65
|
-
|
|
69
|
+
logger.info "#{url} redirects to #{new_uri}"
|
|
66
70
|
next
|
|
67
71
|
end
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else "#{response.code}: #{url}"
|
|
73
|
+
if response.code == '404'
|
|
74
|
+
pinboard.delete(url)
|
|
75
|
+
logger.info "Deleted #{url}"
|
|
76
|
+
elsif response.code != '200'
|
|
77
|
+
logger.info "#{response.code}: #{url}"
|
|
75
78
|
end
|
|
76
79
|
end
|
|
80
|
+
pbar.finish
|
|
81
|
+
logger.close
|
|
77
82
|
puts "\n#{moved} URIs are redirecting to new locations, you might want to fix them." if moved > 0
|
metadata
CHANGED
|
@@ -3,10 +3,10 @@ name: unsavory
|
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
|
5
5
|
segments:
|
|
6
|
+
- 1
|
|
6
7
|
- 0
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
version: 0.3.3
|
|
8
|
+
- 0
|
|
9
|
+
version: 1.0.0
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Michael Kohl
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date:
|
|
17
|
+
date: 2011-03-11 00:00:00 +01:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -32,6 +32,21 @@ dependencies:
|
|
|
32
32
|
version: 0.4.3
|
|
33
33
|
type: :runtime
|
|
34
34
|
version_requirements: *id001
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: progressbar
|
|
37
|
+
prerelease: false
|
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
segments:
|
|
44
|
+
- 0
|
|
45
|
+
- 9
|
|
46
|
+
- 0
|
|
47
|
+
version: 0.9.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
version_requirements: *id002
|
|
35
50
|
description:
|
|
36
51
|
email: citizen428@gmail.com
|
|
37
52
|
executables:
|