Ejemplo n.º 1
0
def check_new_goal(artist, new):
    """Checks if a track hits a new stream goal (fixed to 10 million)

    It tweets if a track reaches a new goal

    Args:
      - artist: dictionary that contains all the data about the single artist
      - new: a list of dictionaries with track id, name and number of streams

    Returns:
      an artist dictionary with updated data
    """

    if "kworb" in artist:
        old = artist["kworb"]
        for old_song in old:
            for new_song in new:
                if new_song["id"] == old_song["id"]:
                    if convert_num("10M", old_song["streams"]) != convert_num(
                            "10M", new_song["streams"]):
                        twitter_post(
                            "{} reached {} streams on #Spotify\n{}\n{}".format(
                                new_song["name"],
                                display_num(new_song["streams"]),
                                link_song(new_song["id"]), hashtags))

    artist["kworb"] = new
    return artist
Ejemplo n.º 2
0
def youtube_check_channel_change(old_channel, new_channel, hashtags):
    """Checks if there is any change in the number of subscribers or total views of the channel

    It compares the old channel data with the new (already fetched) data.

    Args:
      - old_channel: dictionary that contains all the old data of the channel
      - new_channel: dictionary that contains all the updated data of the channel
      - hashtags: hashtags to add to the Tweet

    Returns:
      a dictionary with updated data of the channel
    """

    # Tweet if subs reach a new 100 thousands
    if convert_num("100K", new_channel["subs"]) != convert_num(
            "100K", old_channel["subs"]):
        twitter_post_image("{} reached {} subscribers on #YouTube\n{}".format(
            new_channel["name"], display_num(new_channel["subs"],
                                             decimal=True), hashtags),
                           download_image(new_channel["image"]),
                           display_num(new_channel["subs"],
                                       short=True,
                                       decimal=True),
                           text_size=150)
    old_channel["subs"] = new_channel["subs"]

    # Tweet if total views increase and reach a new mark (based on the views_scale)
    if new_channel["views"] > old_channel["total_views"]:
        if convert_num(old_channel["views_scale"],
                       new_channel["views"]) != convert_num(
                           old_channel["views_scale"],
                           old_channel["total_views"]):
            twitter_post_image(
                "{} reached {} total views on #YouTube\n{}".format(
                    new_channel["name"], display_num(new_channel["views"]),
                    hashtags), download_image(new_channel["image"]),
                display_num(new_channel["views"], short=True))
        old_channel["total_views"] = new_channel["views"]

    old_channel["playlist"] = new_channel["playlist"]
    old_channel["name"] = new_channel["name"]
    old_channel["image"] = new_channel["image"]

    return old_channel
Ejemplo n.º 3
0
def youtube_check_videos_change(name, scale, old_videos, new_videos):
    """Checks if there is any new video

    It compares the old videos list of the artist with the new (already fetched) videos list.
    It tweets if there is a new release or if a video reaches a new views goal.

    Args:
      - name: name of the channel
      - scale: number scale that triggers a new views goal (example: reaches a new million, a new billion...)
      - old_videos: list that contains all the old videos
      - new_videos: list that contains all the updated videos

    Returns:
      new_videos
    """

    if old_videos is not None:
        for new_video in new_videos:
            found = False
            for old_video in old_videos:
                if new_video["url"] == old_video["url"]:
                    found = True
                    # Tweet if a video reaches a new record (based on the scale parameter)
                    if convert_num(scale, new_video["views"]) != convert_num(
                            scale, old_video["views"]):
                        twitter_post_image(
                            "{} reached {} views on #YouTube\n{}\n{} #{}".
                            format(new_video["name"],
                                   display_num(new_video["views"]),
                                   url_video + new_video["url"], hashtags,
                                   name),
                            download_image(new_video["image"]),
                            display_num(new_video["views"], short=True),
                            text_size=100,
                            crop=True)
            if not found:
                twitter_post_image(
                    "#{} uploaded a new #video on #YouTube: {}\n{}\n{}".format(
                        name, new_video["name"], url_video + new_video["url"],
                        hashtags),
                    download_image(new_video["image"]),
                    "NEW",
                    text_size=100,
                    crop=True)
    return new_videos
Ejemplo n.º 4
0
def get_artist(spotify, artist, hashtags):
    """Gets details about an artist

    It tweets if the artist reaches a new goal of followers on Spotify

    Args:
      - spotify: The Spotify instance
      - artist: dictionary that contains all the data about the single artist
      - hashtags: hashtags to append to the Tweet

    Returns:
      an artist dictionary with updated profile details
    """
    # Generate URI
    artist["uri"] = 'spotify:artist:' + artist["id"]

    artist_details = spotify.artist(artist["uri"])

    artist["name"] = artist_details["name"]
    print("[{}] ({}) Getting details... (ID: {})".format(
        module, artist["name"], artist["id"]))

    artist["popularity"] = artist_details["popularity"]
    artist["genres"] = artist_details["genres"]
    try:
        artist["image"] = artist_details["images"][0]["url"]
    except:
        artist["image"] = None
        print("WARNING: Cannot fetch image of {}".format(artist["name"])
              )  # This fix is needed for artists without a profile image

    if convert_num("100K", artist_details["followers"]["total"]) > convert_num(
            "100K", artist["followers"]):
        artist["followers"] = artist_details["followers"]["total"]
        twitter_post_image(
            "{} reached {} followers on #Spotify\n{}\n{}".format(
                artist["name"], display_num(artist["followers"], decimal=True),
                link_artist(artist["id"]), hashtags),
            download_image(artist["image"]),
            display_num(artist["followers"], short=True, decimal=True),
            text_size=125)

    return artist
Ejemplo n.º 5
0
def instagram_profile(artist):
    """Gets the details of an artist on Instagram

    It tweets if the artist reaches a new followers goal

    Args:
      artist: a dictionary with all the details of the artist

    Returns:
      - an dictionary containing all the updated data of the artist
      - a Profile instance
    """

    print("[{}] ({}) Fetching profile details".format(
        module, artist["instagram"]["url"][26:-1]))

    profile = Profile(artist["instagram"]["url"])
    profile = profile.scrape(headers=headers, inplace=False)
    artist["instagram"]["posts"] = profile.posts
    # Update profile pic
    artist["instagram"]["image"] = profile.profile_pic_url_hd

    # Update followers only if there is an increase (fixes https://github.com/marco97pa/Blackpink-Data/issues/11)
    if profile.followers > artist["instagram"]["followers"]:
        print("[{}] ({}) Followers increased {} --> {}".format(
            module, artist["instagram"]["url"][26:-1],
            artist["instagram"]["followers"], profile.followers))
        if convert_num("M", artist["instagram"]["followers"]) != convert_num(
                "M", profile.followers):
            twitter_post_image(
                "#{} reached {} followers on #Instagram\n{}".format(
                    artist["name"].upper(), display_num(profile.followers),
                    hashtags),
                download_image(artist["instagram"]["image"]),
                display_num(profile.followers, short=True),
                text_size=50)
        artist["instagram"]["followers"] = profile.followers

    return artist, profile
Ejemplo n.º 6
0
def instagram_profile(artist):
    """Gets the details of an artist on Instagram

    It tweets if the artist reaches a new followers goal

    Args:
      artist: a dictionary with all the details of the artist

    Returns:
      - an dictionary containing all the updated data of the artist
      - a Profile ID
    """
    username = artist["instagram"]["url"][26:-1]

    print("[{}] ({}) Fetching profile details".format(module, username))

    user_id = cl.user_id_from_username(username)
    info = cl.user_info(user_id)
    artist["instagram"]["posts"] = info.media_count
    # Update profile pic
    artist["instagram"]["image"] = "{}".format(info.profile_pic_url)

    # Add followers if never happened before
    if "followers" not in artist["instagram"]:
      artist["instagram"]["followers"] = info.follower_count

    # Update followers only if there is an increase (fixes https://github.com/marco97pa/Blackpink-Data/issues/11)
    if info.follower_count > artist["instagram"]["followers"]:
        print("[{}] ({}) Followers increased {} --> {}".format(module, artist["instagram"]["url"][26:-1], artist["instagram"]["followers"], info.follower_count))
        if convert_num("M", artist["instagram"]["followers"]) != convert_num("M", info.follower_count):
            twitter_post_image(
                "{} reached {} followers on #Instagram\n{}".format(artist["name"], display_num(info.follower_count), artist["hashtags"]),
                download_profile_pic(artist["instagram"]["image"]),
                display_num(info.follower_count, short=True),
                text_size=50
                )
        artist["instagram"]["followers"] = info.follower_count
    
    return artist, user_id