runoff 0.1.2 → 0.1.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmUzMWI2ZWE4ZThmNTE1OTk5NmU2MjVhYmIzOGNmOGU5MGUyZDNiYg==
4
+ OTA3ZDMwNGJlZWY3YWE2MTVlMmJjY2RiMWJmYzJjZGI1NzdjNTI0Mw==
5
5
  data.tar.gz: !binary |-
6
- OWZiYzc1Y2I0NzdiN2M0MTExOWEwYTFhZjI0YTJkYzU2N2JmYzg5Zg==
6
+ NzIyYzU3ZDJhM2YyMmYzY2VmYmMxZjhkNzAwY2MxZTBkMzBhY2MyNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTg5NzYxNmZlNWRkMWU3YzkyZmMwMWRkODdkMmY1MTBkM2Y2ZjI2ODU4Yjli
10
- ZDc1ZmU3NjA5ZWU2YWFhNTE2NmZiOWNlNDJlMGYzNzhkYzkxNDlhZjY2MWEz
11
- ZDM5ZjNiNjJlNGJlNmFiZWQzMGRkYWE3N2ZhYmQ5MDFjZGQ2ZGY=
9
+ ODM4OGYzZTBlMDM0MmY2NGYxNTIxYTk3YzkxOTAxY2QzYWU0MmZkY2ZlMjFm
10
+ NTZiMDU3NjgxODJiZTE0MzIxZDM3NjU0NzEwNzQ2ZjMzZGQ5NWUwYTQzZmU5
11
+ NTkwZTg5YTlmNjg0M2NmYTE3MjRhNjI0MWRlN2UyYmMyMDc2OTc=
12
12
  data.tar.gz: !binary |-
13
- YWU1YjU5NDNmZjE3Mjc5Mzk2MmY4ZjE1MWIwNDk0OTQ4MmUxZDE2OTNjOWFj
14
- Y2U0N2UwNTQxM2U5NDJmOTY3YmJhNzE1ODYxMzY0ZDE0ODhiY2E3ZDQ4Nzdh
15
- Y2U3M2FkNDRmNmM3NTM4OWY1NDA1M2E4MmQyN2Q5YmRlOGJmNjI=
13
+ MmRhYzdiNjliNDVhMjIyYmI5YzRmMGM0NThhZDllMjU3ODhhZjM3YjgzMDAy
14
+ NzY4NzQyMDg4NTEyOGEwYzA5YjNhNmNmYWUwMGY3Mzc5N2Y0NjNlZjY3NDAx
15
+ ZmVmYzY3NTVkOWQ1YmE3ODk2Y2RlNmY5MWY5YjM2OGU5ZDBmZTk=
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -30,15 +30,11 @@ If you're confused, you can get some help.
30
30
 
31
31
  runoff help all
32
32
 
33
- ## Problems
34
-
35
- The current version (0.1.1) doesn't support Windows, but it will be fixed soon.
36
-
37
33
  ## What else?
38
34
 
39
35
  Things to do in the future versions:
40
36
 
41
- - Fix sqlite path bug in Windows.
37
+ - Parse body_xml to filter XML tags and character entities.
42
38
  - Append only new messages to the previously genetrated files instead of appending everything or create different versions for the files.
43
39
  - Add some colors.
44
40
 
@@ -2,7 +2,6 @@ require 'sequel'
2
2
  require 'set'
3
3
 
4
4
  module Runoff
5
-
6
5
  # Public: Provides interaction with a Skype database file.
7
6
  #
8
7
  # Examples
@@ -10,6 +9,7 @@ module Runoff
10
9
  # composition = Composition.new 'path/to/the/main.db'
11
10
  # exported_files_count = composition.export 'export/folder'
12
11
  class Composition
12
+ include FileWriter
13
13
 
14
14
  # Public: Returns a Set object of all the names of the exported files.
15
15
  attr_reader :exported_filenames
@@ -35,16 +35,14 @@ module Runoff
35
35
  #
36
36
  # Examples
37
37
  #
38
- # export '~/skype_backup'
38
+ # export '/home/username/skype_backup'
39
39
  # # => 8
40
40
  #
41
41
  # Returns the count of the exported files.
42
42
  def export(destination_path)
43
43
  chat_records = @messages.select(:chatname, :timestamp, :from_dispname, :body_xml)
44
44
 
45
- chat_records.each { |record| save_to_file record, destination_path }
46
-
47
- @exported_filenames.count
45
+ run_export chat_records, destination_path
48
46
  end
49
47
 
50
48
  # Public: Gets parsed chatnames together with partly parsed chatnames.
@@ -78,86 +76,29 @@ module Runoff
78
76
  pattern_chatnames = chatnames.map { |name| "#{name}%" }
79
77
  chat_records = @messages.where(Sequel.like(:chatname, *pattern_chatnames))
80
78
 
81
- chat_records.each { |record| save_to_file record, destination_path }
82
-
83
- @exported_filenames.count
79
+ run_export chat_records, destination_path
84
80
  end
85
81
 
86
82
  private
87
83
 
88
- # Internal: Saves a single chat message to a file.
89
- #
90
- # chat_record - a Hash containing data about a single chat message.
91
- # output_directory - A String with the path to the directory, wher the file will be saved.
84
+ # Internal: Performs the export process.
85
+ #
86
+ # chat_records -
92
87
  Array of chat records read from database
93
88
  #
94
89
  # Examples
95
90
  #
96
- # save_to_file record, '~/skype_backup'
97
- def save_to_file(chat_record, output_directory)
98
- datetime = Time.at chat_record[:timestamp]
99
- output_record = "[#{datetime.to_date}] #{chat_record[:from_dispname]}: #{chat_record[:body_xml]}"
100
- filename = "#{output_directory}/#{parse_chatname chat_record[:chatname]}.txt"
101
-
102
- File.open(filename, 'a') do |file|
103
- file.puts output_record
91
+ # run_export [{chatname: '#sadsad/$kjhkjh;9878977', 123123213, 'Aidzis', ''}]
92
+ # # => 1
93
+ #
94
+ # Returns the count of the exported files.
95
+ def run_export(chat_records, destination_path)
96
+ chat_records.each do |record|
97
+ if filename = save_to_file(record, destination_path)
98
+ @exported_filenames << filename
99
+ end
104
100
  end
105
101
 
106
- @exported_filenames << filename
107
- rescue StandardError
108
- puts 'An error occured while parsing a chatname'
109
- end
110
-
111
- # Internal: Converts chatname from database to a valid file name.
112
- #
113
- # raw_chatname - A String with a chatname read from the database.
114
- #
115
- # Examples
116
- #
117
- # parse_chatname '#someone/$someone_else;521357125362'
118
- # # => someone-someone_else.txt
119
- #
120
- # Returns a String with a valid file name.
121
- def parse_chatname(raw_chatname)
122
- match = raw_chatname.match(/#(.+)\/\$(.+);|#(.+)\/\$/)
123
- first_part, second_part, third_part = match.captures
124
- chatname = "#{first_part}-#{second_part}-#{third_part}"
125
-
126
- trim_dashes chatname
127
- end
128
-
129
- # Internal: Removes extra characters from the end of a chatname.
130
- #
131
- # raw_chatname - A String with a chatname read from the database
132
- #
133
- # Examples
134
- #
135
- # partly_parse_chatname '#someone/$someone_else;521357125362'
136
- # # => #someone/$someone_else;
137
- #
138
- # Returns a String with a chatname without extra characters at the end.
139
- def partly_parse_chatname(raw_chatname)
140
- match = raw_chatname.match(/(#.+\/\$.+;)|(#.+\/\$)/)
141
- first_group, second_group = match.captures
142
-
143
- first_group || second_group
144
- end
145
-
146
- # Internal: Removes unnecessary dashes from the begining and the end of the string.
147
- #
148
- # string - A String possibly containing dashes at the beggining or the end
149
- #
150
- # Examples
151
- #
152
- # str = '--example-'
153
- # trim_dashes str
154
- # # => example
155
- #
156
- # Returns a string without leading and ending dashes.
157
- def trim_dashes(string)
158
- string.gsub! /^-+/, ''
159
- string.gsub! /-+$/, ''
160
-
161
- string
102
+ @exported_filenames.count
162
103
  end
163
104
  end
164
105
  end
@@ -0,0 +1,93 @@
1
+ module Runoff
2
+ # Public: Methods used for writing to files.
3
+ module FileWriter
4
+ # Public: Saves a single chat message to a file.
5
+ #
6
+ # chat_record - a Hash containing data about a single chat message.
7
+ # output_directory - A String with the path to the directory, wher the file will be saved.
8
+ #
9
+ # Examples
10
+ #
11
+ # save_to_file record, '/home/username/skype_backup'
12
+ def save_to_file(chat_record, output_directory)
13
+ datetime = Time.at chat_record[:timestamp]
14
+ output_record = "[#{datetime.strftime "%Y-%m-%d %H:%M:%S"}] "
15
+ output_record << "#{chat_record[:from_dispname]}: #{parse_body_xml chat_record[:body_xml]}"
16
+ filename = "#{output_directory}/#{parse_chatname chat_record[:chatname]}.txt"
17
+
18
+ File.open(filename, 'a') do |file|
19
+ file.puts output_record
20
+ end
21
+
22
+ filename
23
+ rescue StandardError
24
+ puts 'An error occured while parsing a chatname'
25
+ end
26
+
27
+ # Internal: Converts chatname from database to a valid file name.
28
+ #
29
+ # raw_chatname - A String with a chatname read from the database.
30
+ #
31
+ # Examples
32
+ #
33
+ # parse_chatname '#someone/$someone_else;521357125362'
34
+ # # => someone-someone_else.txt
35
+ #
36
+ # Returns a String with a valid file name.
37
+ def parse_chatname(raw_chatname)
38
+ match = raw_chatname.match(/#(.+)\/\$(.+);|#(.+)\/\$/)
39
+ first_part, second_part, third_part = match.captures
40
+ chatname = "#{first_part}-#{second_part}-#{third_part}"
41
+
42
+ trim_dashes chatname
43
+ end
44
+
45
+ # Internal: Removes extra characters from the end of a chatname.
46
+ #
47
+ # raw_chatname - A String with a chatname read from the database
48
+ #
49
+ # Examples
50
+ #
51
+ # partly_parse_chatname '#someone/$someone_else;521357125362'
52
+ # # => #someone/$someone_else;
53
+ #
54
+ # Returns a String with a chatname without extra characters at the end.
55
+ def partly_parse_chatname(raw_chatname)
56
+ match = raw_chatname.match(/(#.+\/\$.+;)|(#.+\/\$)/)
57
+ first_group, second_group = match.captures
58
+
59
+ first_group || second_group
60
+ end
61
+
62
+ # Internal: Removes unnecessary dashes from the begining and the end of the string.
63
+ #
64
+ # string - A String possibly containing dashes at the beggining or the end
65
+ #
66
+ # Examples
67
+ #
68
+ # str = '--example-'
69
+ # trim_dashes str
70
+ # # => example
71
+ #
72
+ # Returns a string without leading and ending dashes.
73
+ def trim_dashes(string)
74
+ clean_string = string.gsub /^-+/, ''
75
+ clean_string.gsub /-+$/, ''
76
+ end
77
+
78
+ # Public: Remove Skype emotion tags.
79
+ #
80
+ # text -
81
  String containing XML data
82
+ #
83
+ # Examples
84
+ #
85
+ # parse_body_xml "Some text <ss type="laugh">:D</ss>"
86
+ # # => "Some text :D"
87
+ #
88
+ # Returns the duplicated String.
89
+ def parse_body_xml(text)
90
+ clean_text = text.gsub /<ss type=".+">/, ''
91
+ clean_text.gsub /<\/ss>/, ''
92
+ end
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module Runoff
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/runoff.rb CHANGED
@@ -1,4 +1,7 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
1
3
  require "runoff/version"
2
4
  require "runoff/location"
5
+ require "runoff/file_writer"
3
6
  require "runoff/composition"
4
7
  require "runoff/source"
@@ -13,41 +13,6 @@ describe Runoff::Composition do
13
13
  @composition.must_respond_to :exported_filenames
14
14
  end
15
15
 
16
- it "must remove all starting and ending dashes from a string" do
17
- string = "---example--"
18
- valid_name = @composition.send :trim_dashes, string
19
-
20
- valid_name.must_equal 'example'
21
- end
22
-
23
- it "must return a valid and readable name from a raw chatname" do
24
- raw_chatname = '#something/$else;521357125362'
25
- chatname = @composition.send :parse_chatname, raw_chatname
26
-
27
- chatname.must_equal 'something-else'
28
- end
29
-
30
- it "must return a valid and readable name from broken chatname records" do
31
- raw_chatname = '#something/$521357125362'
32
- chatname = @composition.send :parse_chatname, raw_chatname
33
-
34
- chatname.must_equal 'something'
35
- end
36
-
37
- it "must return a chatname without the extra symbols" do
38
- raw_chatname = '#something/$else;521357125362'
39
- chatname = @composition.send :partly_parse_chatname, raw_chatname
40
-
41
- chatname.must_equal '#something/$else;'
42
- end
43
-
44
- it "must return a chatname without the extra symbols for broken chatname records" do
45
- raw_chatname = '#something/$521357125362'
46
- chatname = @composition.send :partly_parse_chatname, raw_chatname
47
-
48
- chatname.must_equal '#something/$'
49
- end
50
-
51
16
  it "must return parsed chatnames together with partly parsed chatnames" do
52
17
  chatnames, raw_chatnames = @composition.get_chatnames
53
18
 
@@ -55,63 +20,37 @@ describe Runoff::Composition do
55
20
  raw_chatnames.must_equal ['#something/$more;', '#something/$else;']
56
21
  end
57
22
 
58
- describe "#save_to_file" do
59
- before do
60
- @composition = Runoff::Composition.new 'test/test_db.sqlite'
61
- @incorrect_chat_record = {
62
- chatname: '#something/$;521357125362',
63
- timestamp: 1362864487,
64
- from_dispname: 'Aidzis',
65
- body_xml: ''
66
- }
67
- @chat_record = {
68
- chatname: '#something/$more;521357125362',
69
- timestamp: 1362864487,
23
+ it "must have a save_to_file method" do
24
+ @composition.must_respond_to :save_to_file
25
+ end
26
+
27
+ it "must return a count of the exported filenames" do
28
+ file_count = @composition.send(
29
+ :run_export,
30
+ [{
31
+ chatname: '#test/$one;7687623',
32
+ timestamp: 123123213,
70
33
  from_dispname: 'Aidzis',
71
34
  body_xml: ''
72
- }
73
- end
35
+ }],
36
+ 'test/tmp'
37
+ )
74
38
 
75
- after { FileUtils.rm_rf 'test/tmp/.' }
76
-
77
- it "must write chat content to file" do
78
- @incorrect_chat_record[:chatname] = '#something/$else;521357125362'
79
-
80
- @composition.send :save_to_file, @chat_record, 'test/tmp'
81
- @composition.send :save_to_file, @incorrect_chat_record, 'test/tmp'
82
- @composition.exported_filenames.count.must_equal 2
83
- end
84
-
85
- it "must append to a file if the filename already exists" do
86
- @incorrect_chat_record[:chatname] = '#something/$else;521357125362'
87
- @additional_chat_record = @chat_record
88
-
89
- @composition.send :save_to_file, @chat_record, 'test/tmp'
90
- @composition.send :save_to_file, @incorrect_chat_record, 'test/tmp'
91
- @composition.send :save_to_file, @additional_chat_record, 'test/tmp'
92
- @composition.exported_filenames.count.must_equal 2
93
- end
39
+ file_count.must_equal 1
40
+ FileUtils.rm_rf 'test/tmp/.'
94
41
  end
95
42
 
96
- describe "#export" do
97
- after { FileUtils.rm_rf 'test/tmp/.' }
98
-
99
- it "must return a count of the exported filenames" do
100
- composition = Runoff::Composition.new 'test/test_db.sqlite'
101
- file_count = composition.export 'test/tmp'
43
+ it "must return a count of the exported filenames when called for all chats" do
44
+ file_count = @composition.export 'test/tmp'
102
45
 
103
- file_count.must_equal 2
104
- end
46
+ file_count.must_equal 2
47
+ FileUtils.rm_rf 'test/tmp/.'
105
48
  end
106
49
 
107
- describe "#export_chats" do
108
- after { FileUtils.rm_rf 'test/tmp/.' }
109
-
110
- it "must return a count of the exported filenames" do
111
- composition = Runoff::Composition.new 'test/test_db.sqlite'
112
- file_count = composition.export_chats ['#something/$more;', '#something/$else;'], 'test/tmp'
50
+ it "must return a count of the exported filenames when called for specific chats" do
51
+ file_count = @composition.export_chats ['#something/$more;', '#something/$else;'], 'test/tmp'
113
52
 
114
- file_count.must_equal 2
115
- end
53
+ file_count.must_equal 2
54
+ FileUtils.rm_rf 'test/tmp/.'
116
55
  end
117
56
  end
@@ -0,0 +1,87 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'runoff'
4
+
5
+ describe Runoff::FileWriter do
6
+ before do
7
+ @incorrect_chat_record = {
8
+ chatname: '#something/$;521357125362',
9
+ timestamp: 1362864487,
10
+ from_dispname: 'Aidzis',
11
+ body_xml: ''
12
+ }
13
+ @chat_record = {
14
+ chatname: '#something/$more;521357125362',
15
+ timestamp: 1362864487,
16
+ from_dispname: 'Aidzis',
17
+ body_xml: ''
18
+ }
19
+
20
+ class ClassWithFileWriterMixin
21
+ include Runoff::FileWriter
22
+ end
23
+
24
+ @test_object = ClassWithFileWriterMixin.new
25
+ end
26
+
27
+ it "must return a string without Skype emotion XML tags" do
28
+ string = 'Some text <ss type="laugh">:D</ss>'
29
+ clean_string = @test_object.parse_body_xml string
30
+
31
+ clean_string.must_equal 'Some text :D'
32
+ end
33
+
34
+ it "must remove all starting and ending dashes from a string" do
35
+ string = "---example--"
36
+ valid_name = @test_object.trim_dashes string
37
+
38
+ valid_name.must_equal 'example'
39
+ end
40
+
41
+ it "must return a valid and readable name from a raw chatname" do
42
+ raw_chatname = '#something/$else;521357125362'
43
+ chatname = @test_object.parse_chatname raw_chatname
44
+
45
+ chatname.must_equal 'something-else'
46
+ end
47
+
48
+ it "must return a valid and readable name from broken chatname records" do
49
+ raw_chatname = '#something/$521357125362'
50
+ chatname = @test_object.parse_chatname raw_chatname
51
+
52
+ chatname.must_equal 'something'
53
+ end
54
+
55
+ it "must return a chatname without the extra symbols" do
56
+ raw_chatname = '#something/$else;521357125362'
57
+ chatname = @test_object.partly_parse_chatname raw_chatname
58
+
59
+ chatname.must_equal '#something/$else;'
60
+ end
61
+
62
+ it "must return a chatname without the extra symbols for broken chatname records" do
63
+ raw_chatname = '#something/$521357125362'
64
+ chatname = @test_object.partly_parse_chatname raw_chatname
65
+
66
+ chatname.must_equal '#something/$'
67
+ end
68
+
69
+ describe "#save_to_file" do
70
+ after { FileUtils.rm_rf 'test/tmp/.' }
71
+
72
+ it "must write chat content to file" do
73
+ @test_object.save_to_file @chat_record, 'test/tmp'
74
+ @test_object.save_to_file @incorrect_chat_record, 'test/tmp'
75
+ Dir["test/tmp/**/*"].length.must_equal 2
76
+ end
77
+
78
+ it "must append to a file if the filename already exists" do
79
+ @additional_chat_record = @chat_record
80
+
81
+ @test_object.save_to_file @chat_record, 'test/tmp'
82
+ @test_object.save_to_file @incorrect_chat_record, 'test/tmp'
83
+ @test_object.save_to_file @additional_chat_record, 'test/tmp'
84
+ Dir["test/tmp/**/*"].length.must_equal 2
85
+ end
86
+ end
87
+ end
@@ -8,7 +8,7 @@ describe Runoff::Location do
8
8
  path = Runoff::Location.default_skype_data_location 'aidzis_skype'
9
9
 
10
10
  if RbConfig::CONFIG['host_os'] =~ /mingw/
11
- path.must_match /[A-Z]:\\Users\\[a-zA-Z0-9]+\\AppData\\Roaming\\Skype\\aidzis_skype\\main\.db/
11
+ path.must_match /\/Users\/[a-zA-Z0-9]+\/AppData\/Roaming\/Skype\/aidzis_skype\/main\.db/
12
12
  elsif RbConfig::CONFIG['host_os'] =~ /linux/
13
13
  path.must_match /\/home\/[a-zA-Z0-9]+\/\.Skype\/aidzis_skype\/main\.db/
14
14
  else
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aigars Dzerviniks
@@ -39,7 +39,7 @@ cert_chain:
39
39
  dHFPWFp1ck5FWmdTMlRSWG5GRG9TWmRtT3IxMjM2ZS9SNTBzc1dlR0dIUUox
40
40
  V2wKN2ZZbFZpQThPY2Z3aGdyaDcyc05mVHpTCi0tLS0tRU5EIENFUlRJRklD
41
41
  QVRFLS0tLS0K
42
- date: 2013-03-27 00:00:00.000000000 Z
42
+ date: 2013-04-03 00:00:00.000000000 Z
43
43
  dependencies:
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: thor
@@ -101,11 +101,13 @@ files:
101
101
  - gem-public_cert.pem
102
102
  - lib/runoff.rb
103
103
  - lib/runoff/composition.rb
104
+ - lib/runoff/file_writer.rb
104
105
  - lib/runoff/location.rb
105
106
  - lib/runoff/source.rb
106
107
  - lib/runoff/version.rb
107
108
  - runoff.gemspec
108
109
  - test/runoff_composition_test.rb
110
+ - test/runoff_file_writer_test.rb
109
111
  - test/runoff_locations_test.rb
110
112
  - test/runoff_source_test.rb
111
113
  - test/test_db.sqlite
@@ -135,6 +137,7 @@ specification_version: 4
135
137
  summary: Tool to export Skype chat history from the SQLite database to text files
136
138
  test_files:
137
139
  - test/runoff_composition_test.rb
140
+ - test/runoff_file_writer_test.rb
138
141
  - test/runoff_locations_test.rb
139
142
  - test/runoff_source_test.rb
140
143
  - test/test_db.sqlite
metadata.gz.sig CHANGED
Binary file