Skip to content

Instantly share code, notes, and snippets.

@m-bodmer
Last active December 22, 2015 04:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-bodmer/6418471 to your computer and use it in GitHub Desktop.
Save m-bodmer/6418471 to your computer and use it in GitHub Desktop.
Bing news search widget for Dashing

Bing News Search

Live Demo: http://dashingnews.mbodmer.com/sample

Description

This Dashing widget searches Bing news for a topic that you specify. The widget refreshes every 3 hours by default.

Dependencies

Bing search wrapper

Add it to dashing's Gemfile:

gem 'searchbing'

then run bundle install

Also, you need to sign up for a Microsoft developer account (You can use an existing Gmail account or your Windows Live account)

Installation

  1. In your dashboards layout ERB file, add the following widget HTML:
<li data-row="1" data-col="2" data-sizex="2" data-sizey="1">
  <div data-id="bingNews" data-view="NewsList" data-title="Latest News"></div>
</li>
  1. Copy the files news_list.html, news_list.scss and news_list.coffee to a new /widgets/news_listfolder
    • Optionally, you can install this widget with a dashing command (If you do this, skip Step 3)
    • dashing install GIST_ID
  2. Move the bing_news.rb file into the /jobs folder
  3. Edit the news_topic and the bing_account_key variables.
  4. Run dashing startin the command line.
# Bing search wrapper gem: https://github.com/rcullito/searchbing
require 'searchbing'
# Get news for a certain topic
news_topic = 'YOUR_NEWS_TOPIC'
# Primary account key (string) which you can get from https://datamarket.azure.com/account
bing_account_key = 'YOUR_ACCOUNT_KEY'
# If you want to change the date format, just edit the strftime string below according to http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/DateTime.html
date_format = "%b. %d %Y at %l:%M%p"
SCHEDULER.every '3h', :first_in => 0 do |job|
bing_news = Bing.new(bing_account_key, 3, 'News')
news_results = bing_news.search(news_topic)
# Format Bing news date result to be more readable
if news_results
news_results.select { |key|
if key['Date']
date = Time.parse key['Date']
key['Date'].replace date.strftime(date_format)
end
}
send_event('bingNews', {newsItems: news_results, title: "News for: #{news_topic}"})
else
send_event('bingNews', {newsItems: news_results, title: "No News for #{news_topic}"})
end
end
class Dashing.NewsList extends Dashing.Widget
ready: ->
# This is fired when the widget is done being rendered
onData: (data) ->
# Fired when you receive data
# $(@node).fadeOut().fadeIn()
<h1 class="widget-title title" data-bind="title"></h1>
<ul class="news-summary-list">
<li data-foreach-item="newsItems">
<div class="news-summary" data-bind='item.Description | truncate 106'></div>
<div class="meta-info">
<span data-bind='item.Source'></span>
<span>-</span>
<span data-bind='item.Date'></span>
</div>
</li>
</ul>
<!-- Optional: If you would like to show an Updated At message at the bottom of the widget -->
<!-- <p class="updated-at" data-bind="updatedAtMessage"></p> -->
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #12b0c5;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$label-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-list styles
// ----------------------------------------------------------------------------
.widget-news-list {
background-color: $background-color;
// Default widget has vertical-align: middle, so override that style
vertical-align: top !important;
.widget-title {
float: left;
margin-left: 15px;
}
.title {
color: $title-color;
}
// List styles
.news-summary-list {
clear: both;
margin: 0 15px;
text-align: left;
color: $label-color;
}
.news-summary-list li {
margin-bottom: 5px;
}
.news-summary-list li:not(:first-child) {
// Give a top margin to all list items except the 1st one
margin-top: 21px;
}
.list-nostyle {
list-style: none;
}
.news-topic {
color: $label-color;
}
.news-summary {
font-size: 18px;
font-weight: 600;
color: $value-color;
}
.meta-info {
font-size: 16px;
}
// Extra styles
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
@doctorjnupe
Copy link

I cannot get this to work. I'm getting a not permission denied message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment