From a4a4564f760bb1bcd541366186cd46488d5a569b Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Tue, 30 Oct 2012 05:16:35 -0400 Subject: Added new widgets, and made them more flexible. Ready for 0.1.3! --- templates/project/jobs/buzzwords.rb | 2 +- templates/project/jobs/convergence.rb | 1 + templates/project/jobs/sample.rb | 4 ++++ templates/project/jobs/twitter.rb | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 templates/project/jobs/twitter.rb (limited to 'templates/project/jobs') diff --git a/templates/project/jobs/buzzwords.rb b/templates/project/jobs/buzzwords.rb index 109dc60..2668d5a 100644 --- a/templates/project/jobs/buzzwords.rb +++ b/templates/project/jobs/buzzwords.rb @@ -3,7 +3,7 @@ buzzword_counts = Hash.new({ value: 0 }) SCHEDULER.every '2s' do random_buzzword = buzzwords.sample - buzzword_counts[random_buzzword] = { label: random_buzzword, value: buzzword_counts[random_buzzword][:value] + 1 } + buzzword_counts[random_buzzword] = { label: random_buzzword, value: (buzzword_counts[random_buzzword][:value] + 1) % 30 } send_event('buzzwords', { items: buzzword_counts.values }) end \ No newline at end of file diff --git a/templates/project/jobs/convergence.rb b/templates/project/jobs/convergence.rb index f66b6a5..1da2a5b 100644 --- a/templates/project/jobs/convergence.rb +++ b/templates/project/jobs/convergence.rb @@ -1,3 +1,4 @@ +# Populate the graph with some random points points = [] (1..10).each do |i| points << { x: i, y: rand(50) } diff --git a/templates/project/jobs/sample.rb b/templates/project/jobs/sample.rb index 2314dc2..1fe008d 100644 --- a/templates/project/jobs/sample.rb +++ b/templates/project/jobs/sample.rb @@ -1,9 +1,13 @@ current_valuation = 0 +current_karma = 0 SCHEDULER.every '2s' do last_valuation = current_valuation + last_karma = current_karma current_valuation = rand(100) + current_karma = rand(200000) send_event('valuation', { current: current_valuation, last: last_valuation }) + send_event('karma', { current: current_karma, last: last_karma }) send_event('synergy', { value: rand(100) }) end \ No newline at end of file diff --git a/templates/project/jobs/twitter.rb b/templates/project/jobs/twitter.rb new file mode 100644 index 0000000..9359a89 --- /dev/null +++ b/templates/project/jobs/twitter.rb @@ -0,0 +1,17 @@ +require 'net/http' +require 'json' + +search_term = URI::encode('#todayilearned') + +SCHEDULER.every '10m', :first_in => 0 do |job| + http = Net::HTTP.new('search.twitter.com') + response = http.request(Net::HTTP::Get.new("/search.json?q=#{search_term}")) + tweets = JSON.parse(response.body)["results"] + if tweets + tweets.map! do |tweet| + { name: tweet['from_user'], body: tweet['text'], avatar: tweet['profile_image_url_https'] } + end + + send_event('twitter_mentions', comments: tweets) + end +end \ No newline at end of file -- cgit v1.2.3