Ejemplo n.º 1
0
def get_statistic(genre, name):
    """ (str, str) -> (Dictionary, str)
    Makes requests and finds in received
    files necessary information.
    Create the statistic and return
    this statistic in format Dictionary where:
        * keys: words
        * values: number of repeats """
    if isinstance(genre, int):
        genre_url = f"{url}/{genre}/artists"
        genre_data = get_data_from_URL(genre_url)["data"]

        comments = Dictionary()
        for artist in genre_data:
            art_data = get_data_from_URL(
                f'https://api.deezer.com/artist/{artist["id"]}/comments')
            for com in art_data['data']:
                add_to_dict(comments, com["text"])
            while art_data['next']:
                art_data = get_data_from_URL(art_data['next'])
                for com in art_data['data']:
                    add_to_dict(comments, com["text"])

        maximum = dict_to_sorted_list_max_tree(comments)
        return (list_to_dict(maximum), name)
    else:
        return (False, False)
def get_statistic():
    """ () -> (Dictionary)
    Makes requests and finds in received
    files necessary information.
    Create the statistic and return
    this statistic in format Dictionary where:
        * keys: genres
        * values: list( number of artists, number of fans ) """

    data = get_data_from_URL(url)["data"]
    results = Dictionary()

    for genre in data:
        # get information about one genre
        genre_url = f"{url}/{genre['id']}/artists"
        genre_data = get_data_from_URL(genre_url)["data"]

        nb_fan = 0
        for artist in genre_data:
            # get information about one artist (number of fans)
            art_data = get_data_from_URL(
                f'https://api.deezer.com/artist/{artist["id"]}')
            nb_fan += art_data["nb_fan"]

        # add to dictionary received information
        results[genre["name"]] = [len(genre_data), nb_fan]

    return results
Ejemplo n.º 3
0
def list_to_dict(lst):
    """ (list) -> Dictionary
    Return the Dictionary which created of this list
    """
    result = Dictionary()
    for key, number in lst:
        result[key] = number
    return result
Ejemplo n.º 4
0
 def __init__(self):
     """ (Editor) -> NoneType
     Creates tne menu for commands """
     self.menu_map = Dictionary()
     self.menu_map["1"] = self.genre_art_fan_editor
     self.menu_map["2"] = self.com_genre_editor
     self.menu_map["3"] = self.chart_art_editor
     self.menu_map["4"] = self.chart_alb_editor
     self.menu_map["exit"] = self.system_exit
def get_statistic():
    """ () -> (Dictionary)
    Makes requests and finds in received
    files necessary information.
    Create the statistic and return
    this statistic in format Dictionary where:
        * keys: genre
        * values: Dictionary where:
            * keys: string -> (genre: album name)
            * values: number of fans (of the same album) """
    data = get_data_from_URL(
        'https://api.deezer.com/chart/0/albums')['data']
    results = Dictionary()
    for album in data:
        alb_data = get_data_from_URL(
            f'https://api.deezer.com/album/{album["id"]}')
        
        nb_fan = alb_data["fans"]
        for genre in alb_data["genres"]["data"]:
            if not results[genre["name"]]:
                results[genre["name"]] = Dictionary()
            results[genre["name"]][album['title']] = nb_fan
    return results
Ejemplo n.º 6
0
def into_atd(py_dict):
    """ (dict) -> Dictionary
    Return Dictionary created of python dictionary
    """
    our_dict = Dictionary()
    for key, value in py_dict.items():
        if isinstance(value, dict):
            our_dict[key] = into_atd(value)
        elif isinstance(value, list):
            our_dict[key] = value
        else:
            our_dict[key] = value

    return our_dict
Ejemplo n.º 7
0
def get_statistic():
    """ () -> (Dictionary)
    Makes requests and finds in received
    files necessary information.
    Create the statistic and return
    this statistic in format Dictionary where:
        * keys: string -> (rating place + artist name)
        * values: list( number of albums, number of fans ) """
    data = get_data_from_URL('https://api.deezer.com/chart/0/artists')['data']
    results = Dictionary()
    counter = 1
    for artist in data:
        art_data = get_data_from_URL(
            f'https://api.deezer.com/artist/{artist["id"]}')
        results[str(counter) + ' ' +
                art_data['name']] = [art_data["nb_album"], art_data["nb_fan"]]
        counter += 1
    return results