Created
October 27, 2009 03:43
-
-
Save BanzaiMan/219279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config.plugins.searchline.set_default(:interval, 300) | |
| config.plugins.searchline_multi.set_default(:verbose, false) | |
| config.plugins.searchline_multi.set_default(:searches,[]) | |
| module Termtter::Client | |
| class << self | |
| def delete_task(key) | |
| @task_manager.delete_task(key) # returns nil if task for key is not exist | |
| end | |
| @@searches = [] | |
| def add_search(*query) | |
| query_text = query.join(" ") | |
| if ! @@searches.include? [query_text.object_id, query_text] | |
| @@searches << [query_text.object_id, query_text] | |
| query_text.object_id | |
| else | |
| nil | |
| end | |
| end | |
| def delete_search(search) | |
| deleted = @@searches.delete_at(search.to_i) | |
| if ! deleted.nil? | |
| delete_task("searchline_multi_#{deleted[0]}".to_sym) | |
| puts "Deleted: #{deleted[1]}" | |
| else | |
| warn "Do not know anything about '#{deleted.inspect}'" | |
| end | |
| end | |
| def list_searches | |
| @@searches.each_index do |i| | |
| puts "#{i}: #{@@searches[i][1]}" | |
| end | |
| end | |
| def add_search_task(*args) | |
| search_index = add_search(*args) | |
| return unless search_index | |
| public_storage["searchline_since_#{search_index}".to_sym] = 0 | |
| add_task(:name => "searchline_multi_#{search_index}".to_sym, | |
| :interval => config.plugins.searchline.interval ) do | |
| begin | |
| statuses = Termtter::API.twitter.search( | |
| args.join(" "), 'since_id' => public_storage["searchline_since_#{search_index}".to_sym] ) | |
| unless statuses.empty? | |
| print "\e[0G" + "\e[K" unless win? | |
| public_storage["searchline_since_#{search_index}".to_sym] = statuses[0].id | |
| output(statuses, SearchEvent.new(args.join(" "))) | |
| Readline.refresh_line | |
| end | |
| rescue Exception => e | |
| handle_error(e) | |
| end | |
| end | |
| end | |
| end | |
| config.plugins.searchline_multi.searches.each do |str| | |
| add_search_task(str) | |
| end | |
| register_command( | |
| :name => :searchline_multi, | |
| :aliases => [:slm], | |
| :exec => lambda {|*args| | |
| args = args.shift.split | |
| subcommand = args.shift | |
| case subcommand | |
| when /^ad{0,2}$/i | |
| if args.to_a.length == 0 | |
| warn "No search query given" | |
| return | |
| end | |
| add_search_task(*args) | |
| when /^d(e(l(e(te?)?)?)?)?$/i | |
| return unless args[0] =~ /^[0-9]*$/ | |
| delete_search(args[0].to_i) | |
| when /l(i(st?)?)?/ | |
| list_searches | |
| else | |
| warn "Unknown command: #{subcommand}" | |
| end | |
| }, | |
| :help => ["searchline_multi [add [TEXT] | delete # | list ]", "Search for Twitter with auto reload"] | |
| ) | |
| end | |
| # searchline_multi.rb: | |
| # Manage multiple searches with reload | |
| # Caution: | |
| # Be aware of API limit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment