musicfox / pycmc

A Python interface for the chartmetric.com API
MIT License
21 stars 2 forks source link

Fix artist.fanmetrics endpoint #4

Closed thinkjrs closed 4 years ago

thinkjrs commented 4 years ago

Our fanmetrics endpoint is semi-broken, as you can see from the lack of valueCol usage, below.


def fanmetrics(cmid, start_date, dsrc="instagram", valueCol="followers"):
    """
    Query the Chartmetric API for artist fan metrics.
    https://api.chartmetric.com/api/artist/:id/stat/:source
    :param cmid:        string or int Chartmetric artist ID
    :param start_date:  string ISO date %Y-%m-%d
    :param dsrc:        string data source, choose from
                        'spotify', 'facebook', 'twitter', 'instagram',
                        'youtube', 'wikipedia', 'bandsintown', 'soundcloud',
                        'facebook_fans_by_country',
                        'facebook_storytellers_by_country' 
    :param valueCol:    string specific data field returned, choose from
                        'followers', 'popularity', 'listeners',
                        'talks', 'subscribers'
    :return:            nested dict, {valueCol: [fanmetrics]},
                        fanmetrics are dictionaries of time-series stats
    """
    urlhandle = f"/artist/{cmid}/stat/{dsrc}"
    params = {"since": start_date}
    data = utilities.RequestData(urlhandle, params)
    return utilities.RequestGet(data)

Furthermore, we should update the docs to reflect changes in upstream documentation.