Skip to content

Instantly share code, notes, and snippets.

@x2on
Last active August 12, 2019 06:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save x2on/7007757c222aacbd102b to your computer and use it in GitHub Desktop.
Save x2on/7007757c222aacbd102b to your computer and use it in GitHub Desktop.
Android Google Play Dashing Widget

#Android Google Play Dashing Widget

Dashing Widget for displaying current Google Play Ratings.

Preview

##Usage

To use this widget, copy google.html, google.coffee, and google.scss into the /widgets/google directory. Put the google.rb file in your /jobs folder. Copy google.yml into your /config folder and set the app_identifier

Add gem 'market_bot' to your Gemfile and run bundle

To include this widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
    <div data-id="Google" data-view="Google" data-title="Play Store"></div>
</li>
class Dashing.Google extends Dashing.Widget
ready: ->
@onData(this)
onData: (data) ->
widget = $(@node)
last_version = @get('last_version')
rating = last_version.average_rating
rating_detail = last_version.average_rating_detail
voters_count = last_version.voters_count
widget.find('.google-rating-value').html( '<div>Average Rating</div><span id="google-rating-integer-value">' + rating + '</span>')
if rating_detail then widget.find('.google-rating-detail-value').html( '<span id="google-rating-integer-value">' + rating_detail + '</span>')
widget.find('.google-voters-count').html( '<span id="google-voters-count-value">' + voters_count + '</span> Reviews' )
<h1 class="title" data-bind="title"></h1>
<div class="google-rating-container">
<div class="google-rating-value" data-bind='google'></div>
<div class="google-rating-detail-value" data-bind='google'></div>
<div class="google-voters-count" data-bind='google'></div>
</div>
#!/usr/bin/env ruby
require 'rubygems'
require 'market_bot'
SCHEDULER.every '4h', :first_in => 0 do |job|
data = {
:last_version => {
average_rating: 0.0,
voters_count: 0
}
}
begin
config_file = File.dirname(File.expand_path(__FILE__)) + '/../config/google.yml'
config = YAML::load(File.open(config_file))
app = MarketBot::Android::App.new(config['app_identifier'])
app.update
data[:last_version][:average_rating] = app.rating
if config['show_detail_rating']
rating_detail = 0.0
number_of_votes = 0
app.rating_distribution.each { |rating_distribution|
rating_detail += rating_distribution[0] * rating_distribution[1]
number_of_votes += rating_distribution[1]
}
if number_of_votes > 0
rating_detail = "%.4f" % (rating_detail / number_of_votes)
end
data[:last_version][:average_rating_detail] = rating_detail
end
data[:last_version][:voters_count] = app.votes
rescue Exception => e
puts "Error: #{e}"
end
if defined?(send_event)
send_event('Google', data)
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #afb0ae;
$title-color: #ffffff;
// ----------------------------------------------------------------------------
// Widget-comment styles
// ----------------------------------------------------------------------------
.widget-google {
background-color: $background-color;
.title {
font-weight: bold;
color: $title-color;
opacity: .9
}
.google-rating-container {
div > div {
font-size: 24px
}
}
.google-rating-value {
font-size: 76px;
color: $title-color;
#google-rating-integer-value {
font-weight: bold;
}
}
.google-voters-count {
font-size: 1.5em;
color: $title-color;
#google-voters-count-value {
font-weight: bold
}
}
}
app_identifier: "com.autoscout24"
show_detail_rating: false
@pdolinaj
Copy link

pdolinaj commented Feb 8, 2016

How do I get the app_identifier ?

@levabd
Copy link

levabd commented Feb 21, 2016

I setup this widget, but all time I have a zero digit as result
image
What did I do wrong?

@MarkySparky
Copy link

Did you configure the google.yml file?

My folder structure is:

  • dashing
  • dashboards
  • config
  • - google.yml
  • jobs
  • - google.rb
  • widgets
  • - google
  • - google.coffee
  • - google.html
  • - google.scss

- public

My google.yml file looks like this:

app_identifier: "com.standardlife.myportfollio"
show_detail_rating: false

I didnt change any other file at all. Initially, I had put the app id in the .rb file, but then realised it got this from the yml instead. Look at your debug logs in the console, does it say 'app identifier cannot be found'? If so, try my app identier and see if that works to help debug.

Gd luck

@MarkySparky
Copy link

You can get the app identifier by browsing to Google play on chrome, finding the app, then looking in the address bar.
Here is mine for instance:
https://play.google.com/store/apps/details?id=com.standardlife.myportfollio

@noloco
Copy link

noloco commented Sep 9, 2016

I get a Error: uninitialized constant MarketBot::Android when starting dashing. Any ideas?

@rogervalles
Copy link

@levabd and @noloco: try to install a prior version of market_bot in your Gemfile. I tried the 0.15.0 version and then it worked:

'market_bot', '0.15.0'

@xelprep
Copy link

xelprep commented Sep 29, 2017

@rogervalles @levabd @noloco Alternatively, you don't need an older market_bot, you just need to change the constant in the script from MarketBot::Android to MarketBot::Play and it should work just fine with the latest version. I know this is 1 year too late, but maybe it will help someone else in the future.

@swetabhmukherjee
Copy link

I keep getting the error like 'Error: undefined method `[]' for nil:NilClass'. I've tried everything that has been mentioned in this section but all in vain. Can someone help me out please @xelprep @rogervalles @MarkySparky

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