Class: Birdwatcher::Modules::Users::Import

Inherits:
Birdwatcher::Module show all
Defined in:
lib/birdwatcher/modules/users/import.rb

Constant Summary

Constants inherited from Birdwatcher::Module

Birdwatcher::Module::MODULE_PATH

Constants included from Concerns::Concurrency

Concerns::Concurrency::DEFAULT_THREAD_POOL_SIZE

Constants included from Concerns::Core

Concerns::Core::DATA_DIRECTORY

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Birdwatcher::Module

_file_path, _file_path=, descendants, #execute, inherited, meta, meta=, module_by_path, module_paths, modules, path

Methods included from Concerns::Concurrency

included, #thread_pool

Methods included from Concerns::Persistence

included, #save_status, #save_user

Methods included from Concerns::Presentation

included, #make_status_summary_output, #make_url_summary_output, #make_user_details_output, #make_user_summary_output, #output_status_summary, #output_user_details, #output_user_summary, #page_text

Methods included from Concerns::Outputting

#confirm, #error, #fatal, included, #info, #line_separator, #newline, #output, #output_formatted, #task, #warn

Methods included from Concerns::Util

#escape_html, #excerpt, included, #parse_time, #pluralize, #strip_control_characters, #strip_html, #suppress_output, #suppress_warnings, #time_ago_in_words, #unescape_html

Methods included from Concerns::Core

#console, #current_workspace, #current_workspace=, #database, included, #klout_client, #read_data_file, #twitter_client

Class Method Details

.infoObject



18
19
20
21
22
23
24
25
26
# File 'lib/birdwatcher/modules/users/import.rb', line 18

def self.info
<<-INFO
The User Importer module is a simple module to add a large number of users to
the currently active workspace by parsing a file containing screen names.

The file is expected to contain one screen name per line, without the @ sign or
https://twitter.com/ in front of them.
INFO
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/birdwatcher/modules/users/import.rb', line 28

def run
  filename = File.expand_path(option_setting("FILE"))
  if !File.exists?(filename)
    error("File #{filename.bold} does not exist")
    return false
  end
  if !File.readable?(filename)
    error("File #{filename.bold} is not readable")
    return false
  end
  threads = thread_pool
  File.read(filename).each_line do |screen_name|
    threads.process do
      begin
        screen_name.strip!
        next if screen_name.empty?
        if current_workspace.users_dataset.first(:screen_name => screen_name)
          info("User #{screen_name.bold} is already in the workspace")
          next
        end
        user = twitter_client.user(screen_name)
        save_user(user)
        info("Added #{screen_name.bold} to workspace")
      rescue Twitter::Error::NotFound
        error("There is no user with screen name: #{screen_name.bold}")
      end
    end
  end
  threads.shutdown
end