Skip to content

Commit

Permalink
Move archive directory ; Command line option to add new account ; bug…
Browse files Browse the repository at this point in the history
… fixes for new accounts
  • Loading branch information
jmartindf committed Jul 10, 2011
1 parent f6feea7 commit 5bdfadb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
22 changes: 15 additions & 7 deletions aviary.rb
Expand Up @@ -8,6 +8,8 @@
require 'twitter_archiver'
require 'launchy'

AUTH_FILE = "twitauth.yml"

def prompt(default, *args)
if not STDOUT.sync
STDOUT.sync = true
Expand All @@ -22,8 +24,7 @@ def prompt(default, *args)
end

def config(username)
auth = "twitauth.yml"
users = YAML.load_file(auth)
users = YAML.load_file(AUTH_FILE)
config = Hash.new()

key = "KYcLNiVtuTb5F55gWuVZQw"
Expand All @@ -48,7 +49,7 @@ def config(username)
config['token'] = access_token.token
config['secret'] = access_token.secret
users[username] = config
File.open( auth, 'w' ) do |out|
File.open( AUTH_FILE, 'w' ) do |out|
YAML.dump( users, out )
end#File.open
end#if not pin.nil?
Expand All @@ -57,7 +58,6 @@ def config(username)
begin

CONFIG = YAML.load_file('config.yml')
USERS = YAML.load_file('twitauth.yml')
$options = {}
$options[:tweet_path] = CONFIG['archive_dir']
OptionParser.new do |opts|
Expand All @@ -67,13 +67,21 @@ def config(username)
opts.on("--updates [new|all]", [:new, :all], "Fetch only new or all updates") {|updates| $options[:updates] = updates}
$options[:page] = 1
opts.on("--page XXX", Integer, "Page") {|page| $options[:page] = page}
$options[:new_account] = nil
opts.on("--add XXX", String, "NewAccount") {|account| $options[:new_account] = account}
end.parse!

if [:updates].map {|opt| $options[opt].nil?}.include?(nil)
puts "Usage: aviary.rb --updates [new|all] --page XXX"
puts "Usage: aviary.rb --updates [new|all] --page XXX --add XXX"
exit
end

if not $options[:new_account].nil?
config($options[:new_account])
end

USERS = YAML.load_file(AUTH_FILE)

case $options[:updates]
when :new
updates_only = true
Expand All @@ -96,8 +104,8 @@ def config(username)
}


rescue Errno::ENOENT
puts "Whoops!"
rescue Errno::ENOENT => e
puts "Whoops! - #{e.message}"
puts "There is no configuration file."
puts "Place your username and password in a file called `config.yml`. See config-example.yml."
rescue RetrieveError => e
Expand Down
2 changes: 1 addition & 1 deletion config.yml
@@ -1,2 +1,2 @@
---
archive_dir: /Users/jmartin/development/aviary
archive_dir: /Users/jmartin/Documents/aviary
25 changes: 18 additions & 7 deletions twitter_archiver.rb
Expand Up @@ -62,12 +62,15 @@ def initialize(user, token, secret, root)
FileUtils.mkdir_p @t_prefix
FileUtils.mkdir_p @dm_prefix

File.foreach(@replies_path) { |line|
track_reply(line.strip) unless line.nil?
}
File.foreach(@lost_replies_path) { |line|
track_reply(line.strip, true)
}
begin
File.foreach(@replies_path) { |line|
track_reply(line.strip) unless line.nil?
}
File.foreach(@lost_replies_path) { |line|
track_reply(line.strip, true)
}
rescue Errno::ENOENT
end
end

def log_replies()
Expand Down Expand Up @@ -112,6 +115,10 @@ def get_most_recent_id(dm=false)
}
# find the most recent status
last_id = $statuses.sort.reverse.first
if last_id==""
last_id=nil
end
last_id
end

def got_reply(id, missing=false)
Expand Down Expand Up @@ -139,7 +146,11 @@ def hark(updates_only, page, api, dm=false)

if updates_only
since_id = get_most_recent_id(dm)
since_id_parameter = "&since_id=#{since_id}"
if not since_id.nil?
since_id_parameter = "&since_id=#{since_id}"
else
since_id_parameter = ""
end
else
since_id_parameter = ""
end
Expand Down

0 comments on commit 5bdfadb

Please sign in to comment.