skygrepe 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fd6ad1e12855a62e7a8a68d2ae3f1dfafe61907
4
- data.tar.gz: 7dd30deed5ab0a00c32f18fb891ccbd3b983149a
3
+ metadata.gz: f22cbaa714bda9bfe76939f658878636c3e0d683
4
+ data.tar.gz: 6d68b271847048f2b1da7302921c567b0ba82f22
5
5
  SHA512:
6
- metadata.gz: 0d1f90f2b5042d047b4838c0a348b1034cad533f9d450a902ffdf0fe1fe19ca8b67694d62f62fbbaad6bc02baf3f02df7150d7dd7da9383af329c3996e0d8ff0
7
- data.tar.gz: 6837017e272240f721d2122a6b1fd356e7d0d276fe5760c71a84b60acfe485cfe7a858079609853551edacd2f0896cd03e4281a751975942f764fcb779e2bafa
6
+ metadata.gz: dfa7220a1da6da334b920443f45a566afc6965872728e0aea0285fbbcd1a7d5954b99ab52224476b733677d139e24f0228b43b870dc29c80c2275629417e83bc
7
+ data.tar.gz: 34dc9c90029fb01fe00ffd13ebd90e3895703cdb03b6b63abeba159a469cc781fddf15f956c726957bec26605abc4abc9d8150212a354c33836029fcac4c7314
data/README.md CHANGED
@@ -1,29 +1,41 @@
1
- # Skygrepe
1
+ # skygrepe
2
2
 
3
- TODO: Write a gem description
3
+ Skype had /search command to search over multi conversations. But it have gone away.
4
+ We need other tools. skygrepe is one of them.
4
5
 
5
6
  ## Installation
6
7
 
7
- Add this line to your application's Gemfile:
8
+ $ gem install skygrepe
8
9
 
9
- gem 'skygrepe'
10
+ If you use rbenv, you should run
10
11
 
11
- And then execute:
12
+ $ rbenv rehash
12
13
 
13
- $ bundle
14
+ ## Usage
14
15
 
15
- Or install it yourself as:
16
+ $ skygrepe KEYWORD
16
17
 
17
- $ gem install skygrepe
18
+ ### First time
18
19
 
19
- ## Usage
20
+ Before searching, skygrepe require path to database of Skype.
21
+
22
+ ```
23
+ $ skygrepe fooobar
24
+ 1 /Users/akima/Library/Application Support/Skype/takeshi_akima/main.db
25
+ 2 Other
26
+ Choose path:
27
+ ```
28
+
29
+ Enter the number of skype path. If you choose "Other",
30
+
31
+ ```
32
+ please type path/to/main.db:
33
+ ```
20
34
 
21
- TODO: Write usage instructions here
22
35
 
23
- ## Contributing
36
+ ## Uninstall
24
37
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
38
+ ```
39
+ $ gem uninstall skygrepe
40
+ $ rm $HOME/.skygrepe
41
+ ```
data/bin/skygrepe CHANGED
@@ -39,7 +39,19 @@ end
39
39
  $LOAD_PATH << File.expand_path("../../lib", __FILE__)
40
40
  require 'skygrepe'
41
41
 
42
- db = Skygrepe::Database.new(config["main_db_path"])
43
- db.grep(ARGV.first).each do |line|
44
- puts line.join("|")
42
+ c =Skygrepe::Context.new(ARGV.first, config)
43
+ while !c.quit?
44
+ rows = c.run
45
+ rows.each do |line|
46
+ puts line.join("|")
47
+ end
48
+ break if c.count <= c.limit
49
+ print("command [next|prev|quit] ")
50
+ if cmd = $stdin.gets
51
+ case cmd.strip
52
+ when /\An/ then c.next
53
+ when /\Ap/ then c.prev
54
+ when /\Aq/ then c.quit
55
+ end
56
+ end
45
57
  end
@@ -1,3 +1,3 @@
1
1
  module Skygrepe
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/skygrepe.rb CHANGED
@@ -1,16 +1,84 @@
1
1
  require "skygrepe/version"
2
2
  require "sqlite3"
3
3
 
4
+ require "time"
5
+
4
6
  module Skygrepe
5
7
 
6
- class Database
7
- def initialize(path)
8
- @impl ||= SQLite3::Database.new(path)
8
+ class Context
9
+ attr_reader :count, :limit
10
+
11
+ def initialize(keyword, config)
12
+ raise ArgumentError, "keyword is empty" if keyword.nil? || keyword.empty?
13
+ @config = config
14
+ @condition = Condition.new(keyword)
15
+ @offset = 0
16
+ @limit = 30
17
+ @quit = false
18
+ end
19
+
20
+ def quit?
21
+ @quit
22
+ end
23
+
24
+ def db
25
+ @db ||= SQLite3::Database.new(@config["main_db_path"])
26
+ end
27
+
28
+ def run
29
+ @count ||= db.execute(@condition.count_sql).flatten.first.to_i
30
+ formatter = Formatter.new({"time_format" => @config["time_format"]})
31
+ sql = @condition.grep_sql(@limit, @offset)
32
+ rows = db.execute(sql).map{|row| formatter.format(row) }
33
+ if @count <= @limit
34
+ @quit = true
35
+ end
36
+ rows
37
+ end
38
+
39
+ def next(page = 1)
40
+ @offset += (@limit * page)
41
+ end
42
+
43
+ def prev(page = 1)
44
+ self.next( -1 * page)
45
+ end
46
+
47
+ def quit
48
+ @quit = true
49
+ end
50
+ end
51
+
52
+ class Condition
53
+ def initialize(keyword)
54
+ @keyword = keyword
55
+ end
56
+
57
+ def grep_sql(limit, offset)
58
+ sql = "SELECT m.id, m.timestamp, c.displayname, m.author, substr(m.body_xml, 1, 50) FROM Messages as m inner join Conversations as c on m.convo_id = c.id"
59
+ sql << " WHERE body_xml like '%#{@keyword}%'"
60
+ sql << " ORDER BY m.timestamp"
61
+ sql << " LIMIT #{limit} OFFSET #{offset}"
62
+ sql << ';'
63
+ end
64
+
65
+
66
+ def count_sql
67
+ sql = "SELECT count(*) FROM Messages"
68
+ sql << " WHERE body_xml like '%#{@keyword}%'"
69
+ sql << ';'
70
+ end
71
+ end
72
+
73
+ class Formatter
74
+ def initialize(config)
75
+ @time_format = config["time_format"] || "%Y-%m-%d %H:%M"
9
76
  end
10
77
 
11
- def grep(keyword)
12
- sql = "SELECT m.timestamp, c.displayname, m.author, m.body_xml FROM Messages as m inner join Conversations as c on m.convo_id = c.id WHERE body_xml like '%#{keyword}%';"
13
- rows = @impl.execute(sql)
78
+ def format(row)
79
+ row[1] = Time.at(row[1]).strftime(@time_format)
80
+ row[4] = (row[4] || '').gsub(/[\n\r]/m, '')
81
+ row
14
82
  end
15
83
  end
16
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skygrepe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-16 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3