delicious-cli 0.1.4 → 0.2.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 CHANGED
@@ -1,22 +1,49 @@
1
1
  = Delicious.com Command-line Interface
2
2
 
3
- Locally mirror your delicious links, and search them. Usage:
3
+ == Concept
4
+
5
+ This program lets you locally mirror your delicious links, and quickly search them (with pretty colour-coded results).
6
+
7
+ Usage:
8
+
9
+ delicious <search query>
10
+ or
11
+ dels <search query> (if you're into the brevity thing)
4
12
 
5
- dels <search query>
6
13
 
7
14
  == Installation
8
15
 
9
16
  gem sources --add http://gemcutter.org
10
17
  gem install delicious-cli
11
18
 
12
- == Example:
13
19
 
14
- === Set your delicious login information:
20
+ == Configuration
21
+
22
+ Just run "delicious" with no options and it will prompt you for your login and password and save the settings to ~/.delicious.
23
+
24
+
25
+ == Commandline options:
26
+
27
+ Usage: delicious [options] <search query>
28
+
29
+ Specific options:
30
+ -s, --sync Synchronize links
31
+ -r, --redownload Erase database and redownload all links
32
+ -c, --config Configure login info (set delicious username/password)
33
+ -t, --test-auth Test that authentication info works
34
+ -d, --debug Debug info
35
+
36
+ Common options:
37
+ -v, --version Version information
38
+ -h, --help Show this message
39
+
40
+
41
+ == Common Tasks
42
+
15
43
 
16
- (If you have never configured delicious-cli before, this will automatically
17
- happen the first time you run it.)
44
+ === Change your login information:
18
45
 
19
- epi@fizz$ dels -c
46
+ epi@fizz$ delicious -c
20
47
 
21
48
  Delicious login info
22
49
  ---------------------------
@@ -31,36 +58,27 @@ happen the first time you run it.)
31
58
  |_ Login successful! Saving config...
32
59
 
33
60
 
34
- === Download all your delicious links:
61
+ === Download new links (since last update):
35
62
 
36
- epi@fizz$ dels -r
37
-
38
- * Redownloading database...
39
- * Retrieving all links... (3465 links found)
40
- * Inserting links into database...done!
41
-
42
- === Download new links (since last sync):
43
-
44
- epi@fizz$ dels -s
63
+ epi@fizz$ delicious -s
45
64
 
46
65
  * Synchronizing database...
47
- * Retrieving new links... (5 links found)
48
- * Inserting links into database...done!
66
+ |_ Retrieving new links... (5 links found)
67
+ |_ Processing links...done!
68
+ |_ Saving database...done!
49
69
 
50
- == Commandline options:
70
+
71
+ === Clear the database and redownload all links:
51
72
 
52
- Usage: dels [options] <search query>
73
+ epi@fizz$ delicious -r
53
74
 
54
- Specific options:
55
- -d, --debug Debug info
56
- -s, --sync Synchronize links
57
- -r, --redownload Erase database and redownload all links
58
- -c, --config Configure app (set delicious username/password)
59
- -t, --test-auth Test that authentication info works
75
+ * Redownloading database...
76
+ |_ Retrieving all links... (3483 links found)
77
+ |_ Processing links...done!
78
+ |_ Saving database...done!
60
79
 
61
- Common options:
62
- -h, --help Show this message
63
80
 
64
81
  == Copyright
65
82
 
66
- Copyright (c) 2009 Chris Gahan. See LICENSE for details.
83
+ Copyright (c) 2009 Chris Gahan. See LICENSE for more details.
84
+
data/bin/delicious ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path(File.dirname(__FILE__))
4
+
5
+ require 'delicious-cli'
6
+ main
@@ -23,10 +23,10 @@ class Delicious
23
23
  [result["posts"]["post"]].flatten # ensure it's an array
24
24
  end
25
25
 
26
- def self.posts_since(time)
27
- $log.debug "Retrieving links newer than #{time}"
28
- results = posts_all(:fromdt=>time)
29
- results.select { |r| r["time"] != time }
26
+ def self.posts_since(time_string)
27
+ $log.debug "Retrieving links newer than #{time_string}"
28
+ results = posts_all(:fromdt=>time_string)
29
+ results.select { |r| r["time"] != time_string }
30
30
  end
31
31
 
32
32
  def self.valid_auth?
@@ -1,17 +1,8 @@
1
- require 'sequel'
2
- require 'sequel/extensions/blank'
3
-
4
1
  require 'delicious-cli/settings'
5
2
  require 'delicious-cli/api'
6
3
 
7
4
  #################################################################
8
5
 
9
- $log.debug "Loading database..."
10
- DB = Sequel.sqlite(configfile('delicious.db'))
11
- $log.debug "done."
12
-
13
- #################################################################
14
-
15
6
  =begin
16
7
  Sample record:
17
8
 
@@ -29,43 +20,40 @@ Sample record:
29
20
  #################################################################
30
21
 
31
22
  class Database
32
- @@posts = DB[:posts]
33
23
 
24
+ @@filename = configfile('delicious.marshal')
25
+ @@posts = []
26
+
27
+ def self.posts
28
+ @@posts
29
+ end
30
+
34
31
  def self.init!
35
- create_posts! unless DB.table_exists?(:posts)
36
- end
37
-
32
+ $log.debug "Loading database..."
33
+ @@posts = Marshal.load(open(@@filename)) if File.exists? @@filename
34
+ $log.debug "done."
35
+ end
36
+
38
37
  def self.clear!
39
- DB.drop_table(:posts)
40
- create_posts!
38
+ File.delete @@filename if File.exists? @@filename
39
+ @@posts = []
41
40
  end
42
41
 
43
- def self.create_posts!
44
- DB.create_table :posts do
45
- primary_key :id
46
-
47
- string :href
48
- string :time
49
- string :tag
50
- string :description
51
- text :extended
52
- string :hash
53
- string :meta
54
-
55
- index :hash, {:unique=>true}
56
- index [:description, :extended, :tag]
42
+ def self.save!
43
+ open(@@filename, "w") do |f|
44
+ f.write Marshal.dump(@@posts)
57
45
  end
58
46
  end
59
-
47
+
60
48
  def self.sync(all=false)
61
49
  all = true if @@posts.empty?
62
50
 
63
51
  if all
64
- print "* Retrieving all links..."
52
+ print " |_ Retrieving all links..."
65
53
  STDOUT.flush
66
54
  posts = Delicious.posts_all
67
55
  else
68
- print "* Retrieving new links..."
56
+ print " |_ Retrieving new links..."
69
57
  STDOUT.flush
70
58
  posts = Delicious.posts_since(most_recent_time)
71
59
  end
@@ -74,30 +62,26 @@ class Database
74
62
 
75
63
  puts " (#{posts.size} links found)"
76
64
 
77
- return if posts.empty?
65
+ if posts.size == 0
66
+ puts
67
+ return
68
+ end
78
69
 
79
- print "* Inserting links into database..."
70
+ print " |_ Processing links..."
71
+ posts.each { |post| post["time_string"] = post["time"]; post["time"] = DateTime.parse(post["time_string"]) }
72
+ @@posts += posts.sort_by { |post| post["time"] }
73
+ puts "done!"
80
74
 
81
- counter = 0
82
- for post in posts
83
- counter += 1
84
- begin
85
- add post
86
- rescue Sequel::DatabaseError => e
87
- $log.debug "error: #{e} adding #{post.inspect}"
88
- end
89
-
90
- if counter % 37 == 0
91
- print "."
92
- STDOUT.flush
93
- end
94
- end
75
+ print " |_ Saving database..."
76
+ save!
95
77
 
96
78
  puts "done!"
79
+ puts
97
80
  end
98
81
 
99
82
  def self.most_recent_time
100
- @@posts.order(:time.desc).limit(1).first[:time]
83
+ #@@posts.order(:time.desc).limit(1).first[:time]
84
+ @@posts.last["time_string"]
101
85
  end
102
86
 
103
87
  def self.add(params)
@@ -105,13 +89,18 @@ class Database
105
89
  end
106
90
 
107
91
  def self.find(words)
108
- sequel_query = @@posts
109
- for word in words
110
- pattern = "%#{word}%"
111
- sequel_query = sequel_query.filter(:extended.like(pattern) | :description.like(pattern) | :tag.like(pattern))
92
+
93
+ finders = words.map{|word| /#{word}/i }
94
+ fields = %w[extended description tag]
95
+
96
+ @@posts.select do |post|
97
+ finders.all? do |finder|
98
+ fields.any? do |field|
99
+ post[field].match finder
100
+ end
101
+ end
112
102
  end
113
- sequel_query.order(:time)
114
- end
115
-
103
+
104
+ end
116
105
 
117
106
  end
@@ -32,8 +32,7 @@ end
32
32
 
33
33
  #################################################################
34
34
 
35
- def formatdate(date, width=11)
36
- dt = DateTime.parse(date)
35
+ def formatdate(dt, width=11)
37
36
  time = "%l:%M%P"
38
37
  date = "%d %b %g"
39
38
  #dt.strftime("#{date} #{time}")
@@ -46,14 +45,14 @@ end
46
45
  def display(post, query, indent_size=11)
47
46
  indent = " " * indent_size
48
47
 
49
- date = formatdate(post[:time], indent_size)
50
- desc = post[:description].hilite(query, :light_white)
51
- ext = post[:extended].hilite(query, :white)
52
- url = post[:href].hilite(query, :light_blue)
53
- tags = post[:tag].hilite(query, :light_cyan)
48
+ date = formatdate(post["time"], indent_size)
49
+ desc = post["description"].hilite(query, :light_white)
50
+ ext = post["extended"].hilite(query, :white)
51
+ url = post["href"].hilite(query, :light_blue)
52
+ tags = post["tag"].hilite(query, :light_cyan)
54
53
 
55
54
  puts date + desc
56
- puts indent + ext if post[:extended].any?
55
+ puts indent + ext if post["extended"].any?
57
56
  puts indent + url
58
57
  puts indent + "(".cyan + tags + ")".cyan
59
58
  puts
@@ -29,7 +29,8 @@ end
29
29
  #################################################################
30
30
 
31
31
  unless File.exists? CONFIGDIR
32
- $log.info "* Creating new config directory: #{CONFIGDIR}"
32
+ puts
33
+ puts "* Creating new configuration directory: #{CONFIGDIR}"
33
34
  FileUtils.mkdir_p CONFIGDIR
34
35
  end
35
36
 
data/lib/delicious-cli.rb CHANGED
@@ -40,7 +40,7 @@ def redownload
40
40
  Database.sync
41
41
  end
42
42
 
43
- def config
43
+ def config(first_time = false)
44
44
  # prompt user and stuff
45
45
  puts "Delicious login info"
46
46
  puts "---------------------------"
@@ -64,6 +64,10 @@ def config
64
64
  Settings["username"] = username
65
65
  Settings["password"] = password
66
66
  Settings.save!
67
+
68
+ sync if first_time
69
+
70
+ puts "* Everything is ready. Search away!"
67
71
  else
68
72
  puts " |_ Login failed! (Please check your credentials or network.)"
69
73
  end
@@ -84,7 +88,7 @@ def main
84
88
  begin
85
89
  Settings.load!
86
90
  rescue Errno::ENOENT
87
- config
91
+ config(true)
88
92
  retry
89
93
  end
90
94
 
@@ -96,14 +100,10 @@ def main
96
100
 
97
101
  options = OpenStruct.new
98
102
  OptionParser.new do |opts|
99
- opts.banner = "Usage: dels [options] <search query>"
100
- opts.separator ""
103
+ opts.banner = "Usage: delicious [options] <search query>"
104
+ opts.separator " "
101
105
  opts.separator "Specific options:"
102
106
 
103
- opts.on("-d", "--debug", "Debug info") do |opt|
104
- options.debug = true
105
- end
106
-
107
107
  opts.on("-s", "--sync", "Synchronize links") do |opt|
108
108
  options.sync = true
109
109
  end
@@ -112,7 +112,7 @@ def main
112
112
  options.redownload = true
113
113
  end
114
114
 
115
- opts.on("-c", "--config", "Configure app (set delicious username/password)") do |opt|
115
+ opts.on("-c", "--config", "Configure login info (set delicious username/password)") do |opt|
116
116
  options.config = true
117
117
  end
118
118
 
@@ -120,8 +120,12 @@ def main
120
120
  options.test_auth = true
121
121
  end
122
122
 
123
+ opts.on("-d", "--debug", "Debug info") do |opt|
124
+ options.debug = true
125
+ end
126
+
123
127
 
124
- opts.separator ""
128
+ opts.separator " "
125
129
  opts.separator "Common options:"
126
130
 
127
131
  # No argument, shows at tail. This will print an options summary.
@@ -131,6 +135,13 @@ def main
131
135
  puts
132
136
  exit
133
137
  end
138
+
139
+ opts.on("-v", "--version", "Version information") do |opt|
140
+ versionfile = File.join(File.dirname(File.expand_path(__FILE__)), "..", "VERSION")
141
+ versionstring = open(versionfile).read
142
+ puts "delicious-cli v#{versionstring}"
143
+ puts
144
+ end
134
145
 
135
146
  end.parse!
136
147
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delicious-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
@@ -9,19 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-29 00:00:00 -04:00
13
- default_executable: dels
12
+ date: 2009-09-10 00:00:00 -04:00
13
+ default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: sequel
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: httparty
27
17
  type: :runtime
@@ -42,20 +32,11 @@ dependencies:
42
32
  - !ruby/object:Gem::Version
43
33
  version: "0"
44
34
  version:
45
- - !ruby/object:Gem::Dependency
46
- name: sqlite3-ruby
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
55
- description: A commandline tool which lets you download all your delicious.com links into a local SQLite database and search them (with pretty color-coded results).
35
+ description: A commandline tool which lets you download all your delicious.com links and search them (with pretty color-coded results).
56
36
  email: chris@ill-logic.com
57
37
  executables:
58
38
  - dels
39
+ - delicious
59
40
  extensions: []
60
41
 
61
42
  extra_rdoc_files:
@@ -94,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
75
  requirements: []
95
76
 
96
77
  rubyforge_project:
97
- rubygems_version: 1.3.3
78
+ rubygems_version: 1.3.5
98
79
  signing_key:
99
80
  specification_version: 3
100
81
  summary: Delicious.com commandline interface