Class: Birdwatcher::Modules::Statuses::Kml
- Inherits:
-
Birdwatcher::Module
- Object
- Birdwatcher::Module
- Birdwatcher::Modules::Statuses::Kml
- Defined in:
- lib/birdwatcher/modules/statuses/kml.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
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
.info ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/birdwatcher/modules/statuses/kml.rb', line 23 def self.info <<-INFO KML is a file format used to display geographic data in an Earth browser such as Google Earth. You can create KML files to pinpoint locations, add image overlays, and expose rich data in new ways. KML is an international standard maintained by the Open Geospatial Consortium, Inc. (OGC). This module can generate a KML document containing all statuses with geo information which can be loaded into an application like Google Earth to browse and analyze statuses. The module supports mapping statuses from all or specific users. INFO end |
Instance Method Details
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/birdwatcher/modules/statuses/kml.rb', line 38 def run if option_setting("USERS") users = current_workspace.users_dataset .where("screen_name IN ?", option_setting("USERS").split(" ").map(&:strip)) .order(:screen_name) else users = current_workspace.users_dataset.order(:screen_name) end if users.empty? error("There are no users to process") return false end kml_document = Birdwatcher::KML.new( :name => "Statuses with geo locations" ) users.each do |user| statuses = user.statuses_dataset.where(:geo => true).order(Sequel.desc(:posted_at)).eager(:user) if statuses.count.zero? warn("User #{user.screen_name.bold} has no statuses with geo location; skipping") next end kml_document.add_folder(user.screen_name, :name => "#{user.name} (@#{user.screen_name})", :description => "Statuses from #{user.screen_name}" ) statuses.each do |status| kml_document.add_placemark_to_folder(user.screen_name, :id => status.twitter_id, :name => "@#{escape_html(user.screen_name)}, #{format_date(status.posted_at)}", :description => make_status_description(status), :Snippet => escape_html(excerpt(status.text, 80)), :Style => "<Icon><href>#{escape_html(user.profile_image_url)}</href></Icon>", :Point => "<coordinates>#{escape_html(status.latitude)},#{escape_html(status.longitude)}</coordinates>", :address => "#{escape_html(status.place_name)}, #{escape_html(status.place_country)}", :TimeStamp => escape_html(status.posted_at.strftime('%Y-%m-%dT%l:%M:%S%z')) ) end info "Added #{pluralize(statuses.count, 'status', 'statuses')} from #{user.screen_name.bold}" end File.write(option_setting("DEST"), kml_document.generate) info("Wrote KML document to #{option_setting('DEST').bold}") end |