skygrepe 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +28 -16
- data/bin/skygrepe +15 -3
- data/lib/skygrepe/version.rb +1 -1
- data/lib/skygrepe.rb +74 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f22cbaa714bda9bfe76939f658878636c3e0d683
|
4
|
+
data.tar.gz: 6d68b271847048f2b1da7302921c567b0ba82f22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa7220a1da6da334b920443f45a566afc6965872728e0aea0285fbbcd1a7d5954b99ab52224476b733677d139e24f0228b43b870dc29c80c2275629417e83bc
|
7
|
+
data.tar.gz: 34dc9c90029fb01fe00ffd13ebd90e3895703cdb03b6b63abeba159a469cc781fddf15f956c726957bec26605abc4abc9d8150212a354c33836029fcac4c7314
|
data/README.md
CHANGED
@@ -1,29 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# skygrepe
|
2
2
|
|
3
|
-
|
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
|
-
|
8
|
+
$ gem install skygrepe
|
8
9
|
|
9
|
-
|
10
|
+
If you use rbenv, you should run
|
10
11
|
|
11
|
-
|
12
|
+
$ rbenv rehash
|
12
13
|
|
13
|
-
|
14
|
+
## Usage
|
14
15
|
|
15
|
-
|
16
|
+
$ skygrepe KEYWORD
|
16
17
|
|
17
|
-
|
18
|
+
### First time
|
18
19
|
|
19
|
-
|
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
|
-
##
|
36
|
+
## Uninstall
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
data/lib/skygrepe/version.rb
CHANGED
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
|
7
|
-
|
8
|
-
|
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
|
12
|
-
|
13
|
-
|
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.
|
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-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|