unsavory 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +49 -0
- data/bin/unsavory +67 -0
- data/lib/delicious.rb +30 -0
- metadata +67 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michael Kohl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= unsavory -- get rid of those stale bookmarks!
|
2
|
+
|
3
|
+
unsavory is a little Ruby script which checks your Delicious bookmarks for dead links (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
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
After installing unsavory with
|
8
|
+
|
9
|
+
$ gem install citizen428-unsavory
|
10
|
+
|
11
|
+
you can start it from the command-line like this:
|
12
|
+
|
13
|
+
$ unsavory
|
14
|
+
|
15
|
+
First the script will check if it can find the configuration file '~/.unsavory', which should have the following format:
|
16
|
+
|
17
|
+
user:password
|
18
|
+
|
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
|
+
|
21
|
+
When run, unsavory will generate output similar to this (the real code does show the URLs):
|
22
|
+
|
23
|
+
Enter Delicious username: username
|
24
|
+
Enter Delicious password: *********
|
25
|
+
|
26
|
+
username has 664 bookmarks.
|
27
|
+
Processing URL #0001: OK
|
28
|
+
Processing URL #0002: OK
|
29
|
+
Processing URL #0003: OK
|
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://...
|
38
|
+
|
39
|
+
== Warning
|
40
|
+
|
41
|
+
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
|
+
|
43
|
+
== Todo
|
44
|
+
|
45
|
+
# None right now
|
46
|
+
|
47
|
+
== Author
|
48
|
+
|
49
|
+
Michael Kohl <citizen428[at]gmail[dot]com>
|
data/bin/unsavory
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# Copyright (c) 2009 Michael Kohl
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
5
|
+
%w{rubygems net/http delicious}.each { |x| require x}
|
6
|
+
highline = true
|
7
|
+
begin
|
8
|
+
require 'highline'
|
9
|
+
rescue LoadError
|
10
|
+
highline = false
|
11
|
+
end
|
12
|
+
|
13
|
+
CFG_FILE = File.join(ENV['HOME'], ".#{File.basename($0)}")
|
14
|
+
|
15
|
+
if File.exists?(CFG_FILE)
|
16
|
+
puts "Using config file '#{CFG_FILE}'"
|
17
|
+
user, pass = File.new(CFG_FILE).gets.chomp.split(':')
|
18
|
+
elsif highline
|
19
|
+
hl = HighLine.new
|
20
|
+
user = hl.ask('Enter Delicious username: ')
|
21
|
+
pass = hl.ask('Enter Delicious password: ') { |q| q.echo = "*" }
|
22
|
+
else
|
23
|
+
puts %{
|
24
|
+
Can't find config file '#{CFG_FILE}' and you
|
25
|
+
don't seem to have HighLine installed. Aborting!
|
26
|
+
}
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
delicious = Delicious.new(user, pass)
|
31
|
+
|
32
|
+
begin
|
33
|
+
urls = delicious.get_all_urls
|
34
|
+
rescue => e
|
35
|
+
puts %{
|
36
|
+
I couldn't get your posts from Delicious!
|
37
|
+
|
38
|
+
Either you entered your username/password wrong,
|
39
|
+
or the site is temporarily unreachable.
|
40
|
+
}
|
41
|
+
exit 2
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "\n#{user} has #{urls.length} bookmarks."
|
45
|
+
|
46
|
+
urls.each_with_index do |url, idx|
|
47
|
+
print "Processing URL #%04d: " % (idx+1)
|
48
|
+
uri = URI.parse(url)
|
49
|
+
response = nil
|
50
|
+
|
51
|
+
begin
|
52
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
53
|
+
response = http.head(uri.path.size > 0 ? uri.path : "/")
|
54
|
+
end
|
55
|
+
rescue => e
|
56
|
+
puts "#{e.message} - #{url}"
|
57
|
+
next
|
58
|
+
end
|
59
|
+
|
60
|
+
puts case response.code
|
61
|
+
when '200' then 'OK'
|
62
|
+
when '404' then
|
63
|
+
delicious.delete(url)
|
64
|
+
"Deleted #{url}"
|
65
|
+
else "#{response.code}: #{url}"
|
66
|
+
end
|
67
|
+
end
|
data/lib/delicious.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Delicious
|
4
|
+
include HTTParty
|
5
|
+
base_uri 'https://api.del.icio.us/v1'
|
6
|
+
headers "User-Agent" => "Unsavory"
|
7
|
+
|
8
|
+
API_METHODS = {
|
9
|
+
:all => '/posts/all',
|
10
|
+
:delete => '/posts/delete?url='}
|
11
|
+
|
12
|
+
def initialize(user, password)
|
13
|
+
@options = {:basic_auth => {:username => user, :password => password}}
|
14
|
+
end
|
15
|
+
|
16
|
+
# get_all returns a nested hash, but we want an array of URLs
|
17
|
+
def get_all_urls
|
18
|
+
get_all['posts']['post'].inject([]) { |urls, post| urls << post['href'] }
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(url)
|
22
|
+
self.class.get(API_METHODS[:delete]+url, @options)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def get_all
|
27
|
+
self.class.get(API_METHODS[:all], @options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unsavory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Kohl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-06 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.3
|
24
|
+
version:
|
25
|
+
description: " unsavory is a little Ruby script which checks your Delicious bookmarks for \n dead links (HTTP status code 404) and removes them. Additionally it will \n also inform you about links which return a status code other than 200 (OK). \n"
|
26
|
+
email: citizen428@gmail.com
|
27
|
+
executables:
|
28
|
+
- unsavory
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/delicious.rb
|
35
|
+
- bin/unsavory
|
36
|
+
- ./LICENSE
|
37
|
+
- ./README.rdoc
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/citizen428/unsavory
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Removes outdated links from your Delicious bookmarks
|
66
|
+
test_files: []
|
67
|
+
|