Skip to content

Instantly share code, notes, and snippets.

@x2on
Last active August 12, 2019 06:37
Show Gist options
  • 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
@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