Giter VIP home page Giter VIP logo

python-socialblade's Introduction

Socialblade API wrapper

Socialblade API wrapper.

Examples

Live YouTube subscriber count

Prints PewDiePie's subscriber count in real time.

from socialblade import YouTubeChannel


pewdiepie_channel = YouTubeChannel('UC-lHJZR3Gqxm24_Vd_AJ5Yw')

for sub in pewdiepie_channel.live_subscriber_count_generator():
    print(sub)

You could also just get the subscriber count as it is at the time, like this:

from socialblade import YouTubeChannel


pewdiepie_channel = YouTubeChannel('UC-lHJZR3Gqxm24_Vd_AJ5Yw')

print(pewdiepie_channel.get_subscriber_count())

Export a Channel's Most Viewed Videos Statistics to CSV

In this example we are exporting statistics about PewDiePie's most viewed videos to CSV.

from socialblade import YouTubeChannel
import csv
from datetime import datetime
import locale


locale.setlocale(locale.LC_ALL, '')


def create_more_readable_ints(integer):
    return locale.currency(integer, symbol=False, grouping=True).replace('.00', '').replace(',', "'")


pewdiepie_channel = YouTubeChannel('UC-lHJZR3Gqxm24_Vd_AJ5Yw')

writer = csv.writer(
    open(
        'PewDiePie Most Viewed Videos {}.csv'.format(str(datetime.now().date())),
        'w',
        newline='',
        encoding='utf-8'
    )
)
writer.writerow(
    ['Channel', 'Title', 'Created at', 'Views', 'Comments']
)
for video in pewdiepie_channel.get_most_viewed_videos():
    writer.writerow(
        [
            'PewDiePie',
            video.title,
            str(video.created_at),
            create_more_readable_ints(video.views_num),
            create_more_readable_ints(video.comments_num)
        ]
    )

You could do the same thing to any channel. You could also export different types of statistics about videos, which I will list the functions for them here:

  • socialblade.YouTubeChannel(channel_id).get_latest_videos()
  • socialblade.YouTubeChannel(channel_id).get_most_viewed_videos()
  • socialblade.YouTubeChannel(channel_id).get_highest_rated_videos()
  • socialblade.YouTubeChannel(channel_id).get_most_relevant_videos()

Get live Twitter follower count

The twitter functionality is limited in this wrapper to retrieving follower counts. You could get a twitter users live follower count similer to how you get a youtuber's live follower count:

from socialblade import TwitterUser


donald_trump_twitter = TwitterUser('realdonaldtrump')

for follower in donald_trump_twitter.live_follower_count_generator(request_delay=500):
    print(follower)

You could also get the follower count as it is at the moment, like so:

from socialblade import TwitterUser


donald_trump_twitter = TwitterUser('realdonaldtrump')

print(donald_trump_twitter.get_follower_count())

python-socialblade's People

Contributors

meatyite avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.