Skip to content

Commit

Permalink
record last sync time
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Aug 3, 2012
1 parent 82ee4ea commit e37ac60
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/skype_archive/model.rb
@@ -1,12 +1,13 @@
require "sqlite3"
require "sequel"
require "active_support/core_ext"
require "rest_client"
require "json"
require "base64"

module SkypeArchive
class Model
LAST_SYNC_FILE = "/tmp/skype_archive_last_sync"

attr_reader :account_name

def initialize(account_name)
Expand All @@ -26,12 +27,13 @@ def search(text, options={})
end

def sync
start_time = Time.now.yesterday.at_beginning_of_day.to_i
end_time = Time.now.yesterday.at_midnight.to_i
start_time = last_sync_time
end_time = Time.now.to_i
sync_contacts
sync_conversations
sync_participants
sync_messages(start_time, end_time)
update_sync_file(end_time)
end

def sync_contacts
Expand Down Expand Up @@ -70,6 +72,20 @@ def sync_messages(start_time=0, end_time=Time.now.to_i)
end
end

def last_sync_time
if File.exists?(LAST_SYNC_FILE)
File.read(LAST_SYNC_FILE).to_i
else
Time.now.to_i - 3600 * 24 * 30
end
end

def update_sync_file(time)
File.open(LAST_SYNC_FILE, 'w') do |file|
file.puts time
end
end

private
def connection
@connection ||= Sequel.sqlite(File.expand_path("~/Library/Application\ Support/Skype/#{account_name}/main.db"))
Expand Down

0 comments on commit e37ac60

Please sign in to comment.