Skip to content

Instantly share code, notes, and snippets.

@tfohlmeister
Last active December 29, 2015 19:49
Show Gist options
  • Save tfohlmeister/7719972 to your computer and use it in GitHub Desktop.
Save tfohlmeister/7719972 to your computer and use it in GitHub Desktop.
[dashing] Google Play Stats widget for Dashing!

Description

Dashing widget & job to display a whole lot of Google Play app statistics.

The widget is fully customizable to display only the information needed and is based on the list widget. It extends the base list by another value, making possible to display 2 values for each app beside its name.

A Dashing job fetches statistics for a given array of apps and uses the wonderful Market Bot to parse the Google Play page.

Google Play Stats

##Usage You'll need the gem market_bot so add gem 'market_bot' to your Gemfile and run bundle install from terminal.

The files listthree.coffee, listthree.html and listthree.scss go in the /widget/listthree directory.

The google_play.rb goes into the /jobs directory.

Add following code to your dashingboard.erb file to make the app stats list show up on your dashboard:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="google_play_stats" data-view="Listthree" data-prefix="&Oslash;" data-title="Stats"></div>
</li>

##Settings (jobs.rb) Because the job is so simple there are actually just two settings to look for: The array appIds which holds all the app names you wanna get statistics for and the stats.push(...) command which handles what values are send to the dashboards. Market Bot supports these attributes: :title, :rating, :updated, :current_version, :requires_android, :category, :installs, :size, :price, :content_rating, :description, :votes, :developer, :more_from_developer, :users_also_installed, :related, :banner_icon_url, :banner_image_url, :website_url, :email, :youtube_video_ids, :screenshot_urls, :whats_new, :permissions, :rating_distribution, :html

#!/usr/bin/env ruby
require 'market_bot'
appIds = 'com.instagram.android','com.facebook.katana'
apps = Array.new
appIds.each do |app|
apps.push(MarketBot::Android::App.new(app))
end
SCHEDULER.every '30m', :first_in => 0 do |job|
stats = Array.new
# prepare request
apps.each do |app|
app.update
stats.push({ label: app.title, value: app.rating, count: app.votes})
end
stats.sort! { |a,b| b[:value] <=> a[:value] }
send_event('google_play_stats', { items: stats })
end
class Dashing.Listthree extends Dashing.Widget
ready: ->
if @get('unordered')
$(@node).find('ol').remove()
else
$(@node).find('ul').remove()
<h1 class="title" data-bind="title"></h1>
<ol>
<li data-foreach-item="items">
<span class="label" data-bind="item.label"></span>
<span class="value">(<span data-bind="item.count | shortenedNumber"></span>)</span>
<span class="value" data-bind="item.value | prepend prefix | append suffix"></span>
</li>
</ol>
<ul class="list-nostyle">
<li data-foreach-item="items">
<span class="label" data-bind="item.label"></span>
<span class="value">(<span data-bind="item.count | shortenedNumber"></span>)</span>
<span class="value" data-bind="item.value | prepend prefix | append suffix"></span>
</li>
</ul>
<p class="more-info" data-bind="moreinfo"></p>
<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-listthree {
background-color: $background-color;
vertical-align: top;
.title {
color: $title-color;
}
ol, ul {
margin: 0 15px;
text-align: left;
color: $label-color;
}
ol {
list-style-position: inside;
}
li {
margin-bottom: 5px;
}
.list-nostyle {
list-style: none;
}
.label {
color: $label-color;
}
.value {
float: right;
margin-left: 12px;
font-weight: 600;
color: $value-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
.more-info {
color: $moreinfo-color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment