Skip to content

Instantly share code, notes, and snippets.

@nicknmejia
Last active September 16, 2020 03:20
Show Gist options
  • Select an option

  • Save nicknmejia/0651bb456dd3e62042ee to your computer and use it in GitHub Desktop.

Select an option

Save nicknmejia/0651bb456dd3e62042ee to your computer and use it in GitHub Desktop.

Revisions

  1. nicknmejia revised this gist Mar 25, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,8 @@
    YouTube Channel Statistics Widget
    ------------------------------------------------------------

    Enables tracking of all video views stats in a playlist.
    Super simple dashing widget for displaying your youtube channels stats</br><br/>

    Super simple dashing widget for displaying your youtube channels stats</br>
    Credit to ephigenia and jonasrosland for creating other youtube widgets that I pulled bits and pieces from</br>
    Hugs and kisses to my loved ones. Vote for Nader!

  2. nicknmejia revised this gist Mar 25, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,8 @@ YouTube Channel Statistics Widget

    Enables tracking of all video views stats in a playlist.

    Super simple dashing widget for displaying your youtube channels stats
    Credit to ephigenia and jonasrosland for creating other youtube widgets that I pulled bits and pieces from
    Super simple dashing widget for displaying your youtube channels stats</br>
    Credit to ephigenia and jonasrosland for creating other youtube widgets that I pulled bits and pieces from</br>
    Hugs and kisses to my loved ones. Vote for Nader!

    ```
  3. nicknmejia revised this gist Mar 25, 2016. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    YouTube Channel Statistics Widget
    ------------------------------------------------------------

    Enables tracking of all video views stats in a playlist.

    Super simple dashing widget for displaying your youtube channels stats
    Credit to ephigenia and jonasrosland for creating other youtube widgets that I pulled bits and pieces from
    Hugs and kisses to my loved ones. Vote for Nader!

    ```
    <li data-row="1" data-col="1" data-sizex="3" data-sizey="1">
    <div data-id="youtube_subscribers" data-view="Longnumber" data-title="Youtube Subscribers" style="background-color:#e52d27;"></div>
    </li>
    ```
  4. nicknmejia created this gist Mar 25, 2016.
    31 changes: 31 additions & 0 deletions youtube_count.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env ruby
    require 'net/http'
    require 'openssl'
    require 'json'

    # Super simple dashing widget for displaying your youtube channels stats
    # Credit to ephigenia and jonasrosland for creating other youtube widgets that I pulled bits and pieces from
    # Hugs and kisses to my loved ones. Vote for Nader!

    # Config
    # ------
    youtube_api_key = ENV['YOUTUBE_API_KEY'] || 'YOUR API KEY'
    youtube_channel_id = ENV['YOUTUBE_CHANNEL_KEY'] || 'YOUR CHANNEL ID'


    SCHEDULER.every '1m', :first_in => 0 do |job|
    http = Net::HTTP.new("www.googleapis.com", Net::HTTP.https_default_port())
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE # disable ssl certificate check
    response = http.request(Net::HTTP::Get.new("/youtube/v3/channels?part=statistics&id=#{youtube_channel_id}&key=#{youtube_api_key}"))

    if response.code != "200"
    puts "youtube api error (status-code: #{response.code})\n#{response.body}"
    else
    data = JSON.parse(response.body)

    send_event('youtube_subscribers', current: data["items"][0]["statistics"]["subscriberCount"])
    send_event('youtube_views', current: data["items"][0]["statistics"]["viewCount"])
    send_event('youtube_videos', current: data["items"][0]["statistics"]["videoCount"])
    end
    end