delish 0.5.2 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/delish +5 -5
- data/bin/import_delicious +68 -40
- data/lib/delish_bookmark_search.rb +3 -3
- data/test/test_db +0 -0
- metadata +3 -3
data/bin/delish
CHANGED
@@ -16,14 +16,14 @@ end
|
|
16
16
|
|
17
17
|
#{{{ Output only and debug
|
18
18
|
unless ARGV[1].nil?
|
19
|
-
|
19
|
+
OUTPUT_ONLY = true
|
20
20
|
unless ARGV[2].nil?
|
21
|
-
|
21
|
+
DEBUG = true
|
22
22
|
else
|
23
|
-
|
23
|
+
DEBUG = false
|
24
24
|
end
|
25
25
|
else
|
26
|
-
|
26
|
+
OUTPUT_ONLY = false
|
27
27
|
end
|
28
28
|
#}}}
|
29
29
|
|
@@ -31,7 +31,7 @@ require 'delish_bookmark_search.rb'
|
|
31
31
|
|
32
32
|
delish_bookmark_search = Delish_Bookmark_Search.new(string, db)
|
33
33
|
|
34
|
-
if
|
34
|
+
if OUTPUT_ONLY
|
35
35
|
delish_bookmark_search.each { |bookmark| puts "#{bookmark[1]}: [#{bookmark[0]}]" }
|
36
36
|
else
|
37
37
|
delish_bookmark_search.each { |bookmark| `#{@@DELISH_COMMAND} #{bookmark[0]}` }
|
data/bin/import_delicious
CHANGED
@@ -5,45 +5,64 @@ require 'rexml/document'
|
|
5
5
|
require 'net/https'
|
6
6
|
require 'sqlite3'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
8
|
user = ENV['delish_user']
|
11
9
|
pass = ENV['delish_pass']
|
12
10
|
|
13
11
|
db = SQLite3::Database.new( "#{ENV['HOME']}/.delish" )
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
class ImportDelish
|
14
|
+
|
15
|
+
#{{{ initialize(user, pass, db)
|
16
|
+
def initialize(user, pass, db)
|
17
|
+
@user = user
|
18
|
+
@pass = pass
|
19
|
+
@db = db
|
20
|
+
end
|
21
|
+
#}}}
|
22
|
+
|
23
|
+
#{{{ create_database
|
24
|
+
def create_database
|
25
|
+
# Create the table!!!
|
26
|
+
@db.execute %{
|
27
|
+
CREATE TABLE posts (
|
28
|
+
url VARCHAR(16384),
|
29
|
+
description VARCHAR(255),
|
30
|
+
extended VARCHAR(255),
|
31
|
+
created DATETIME,
|
32
|
+
hash CHAR(32) PRIMARY KEY,
|
33
|
+
accessed DATETIME
|
34
|
+
);
|
35
|
+
}
|
26
36
|
|
27
|
-
db.execute
|
28
|
-
CREATE TABLE post_tags (
|
29
|
-
|
30
|
-
|
31
|
-
);
|
32
|
-
SQL
|
37
|
+
@db.execute %{
|
38
|
+
CREATE TABLE post_tags (
|
39
|
+
hash CHAR(32),
|
40
|
+
tag_id INTEGER
|
41
|
+
);}
|
33
42
|
|
34
|
-
|
35
|
-
|
43
|
+
@db.execute %{
|
44
|
+
CREATE TABLE tags (
|
45
|
+
tag VARCHAR(255) UNIQUE,
|
46
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT
|
47
|
+
);}
|
48
|
+
end
|
49
|
+
#}}}
|
36
50
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
request.basic_auth user, pass
|
42
|
-
response = http.request(request)
|
51
|
+
#{{{ get_all_tags
|
52
|
+
def get_all_tags
|
53
|
+
# User-Agent: required for del.icio.us api
|
54
|
+
agent = 'delish commandline client 0.6.1'
|
43
55
|
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
http = Net::HTTP.new('api.del.icio.us', 443)
|
57
|
+
http.use_ssl = true
|
58
|
+
http.start do |http|
|
59
|
+
request = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent})
|
60
|
+
request.basic_auth @user, @pass
|
61
|
+
response = http.request(request)
|
62
|
+
|
63
|
+
data = REXML::Document.new(response.body)
|
64
|
+
data.elements.each("/posts/post") do |post|
|
65
|
+
@db.execute(
|
47
66
|
"INSERT INTO posts
|
48
67
|
(url, description, extended, created, accessed, hash) VALUES
|
49
68
|
(?, ?, ?, JULIANDAY(?), JULIANDAY(?), ?);",
|
@@ -52,18 +71,27 @@ http.start do |http|
|
|
52
71
|
post.attributes['extended'],
|
53
72
|
post.attributes['time'].chop,
|
54
73
|
post.attributes['time'].chop,
|
55
|
-
post.attributes['hash']
|
56
|
-
)
|
74
|
+
post.attributes['hash'])
|
57
75
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
76
|
+
post.attributes['tag'].split(' ').each do |tag|
|
77
|
+
@db.execute(
|
78
|
+
%{INSERT OR IGNORE INTO tags (tag) VALUES (?);},
|
79
|
+
tag)
|
80
|
+
tag_id = @db.execute( %{ SELECT id FROM tags WHERE tag = ?}, tag)[0]
|
81
|
+
@db.execute(
|
82
|
+
"INSERT INTO post_tags (hash, tag_id)
|
83
|
+
VALUES (?, ?);",
|
84
|
+
post.attributes['hash'],
|
85
|
+
tag_id)
|
86
|
+
end
|
66
87
|
end
|
67
88
|
end
|
89
|
+
end
|
90
|
+
#}}}
|
91
|
+
|
68
92
|
end
|
69
93
|
|
94
|
+
import = ImportDelish.new(user, pass, db)
|
95
|
+
import.create_database
|
96
|
+
import.get_all_tags
|
97
|
+
|
@@ -249,14 +249,14 @@ class Delish_Bookmark_Search
|
|
249
249
|
end
|
250
250
|
|
251
251
|
statement += " FROM posts"
|
252
|
-
@tag_count.times { |i| statement += ", post_tags AS pt#{i}" }
|
252
|
+
@tag_count.times { |i| statement += ", post_tags AS pt#{i}, tags AS t#{i}" }
|
253
253
|
statement += " WHERE "
|
254
|
-
@tag_count.times { |i| statement += "pt#{i}.hash == posts.hash AND " }
|
254
|
+
@tag_count.times { |i| statement += "pt#{i}.hash == posts.hash AND pt#{i}.tag_id = t#{i}.id AND " }
|
255
255
|
|
256
256
|
tag_count = 0
|
257
257
|
@sss.each_with_index do |ssql,i|
|
258
258
|
while ssql.statement.include? "PLACEHOLDER"
|
259
|
-
ssql.statement.sub!("PLACEHOLDER", "
|
259
|
+
ssql.statement.sub!("PLACEHOLDER", "t#{tag_count}.tag")
|
260
260
|
tag_count += 1
|
261
261
|
end
|
262
262
|
statement += ssql.statement
|
data/test/test_db
CHANGED
Binary file
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: delish
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.6.1
|
7
|
+
date: 2007-07-04 00:00:00 -06:00
|
8
8
|
summary: Allows use of del.icio.us bookmarksfrom the commandline with minimum keystrokes
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: frioux@gmail.com
|
12
|
-
homepage: http://
|
12
|
+
homepage: http://delish.rubyforge.com
|
13
13
|
rubyforge_project:
|
14
14
|
description:
|
15
15
|
autorequire:
|