示例#1
0
def getstats(ids):
    yturl = config['YOUTUBE_USER_API']
    data = []
    for uid in ids:
        r = requests.get(yturl.format(uid))
        jsondata = r.json()
        entry = jsondata['entry']
        updated = entry['updated']['$t']
        network = entry['yt$username']['display']

        # fields that don't update often enough
        uselessfields = {'viewCount': 'Video Views', 'totalUploadViews': 'Total Upload Views'}
        fields = {'subscriberCount': 'Subscribers'}
        stats = entry['yt$statistics']

        stat = {
                'network.id': uid,
                'timestamp': datetime(*time.gmtime()[:6]),
                'updated': updated,
                'network': 'YouTube',
                }
        for k in fields.keys():
            stat[fields[k]]= stats[k]
        data.append(stat)

    return prepare_data(data, fields)
示例#2
0
def getstats(ids):
    fburl = config['FACEBOOK_GRAPH_API']
    data = []
    for uid in ids:
        r = requests.get(fburl.format(uid))
        jsondata = r.json()
        data.append({
            'network_id': uid,
            'timestamp': datetime(*time.gmtime()[:6]),
            'likes': jsondata['likes'],
            #'talking.about': jsondata["talking_about_count"]
        })

    return prepare_data(data)
示例#3
0
def getstats(artists):
    global api_key
    data = []

    for artist in artists:
        data_url = config["LASTFM_ARTIST_API"].format(artist=artist, api_key=api_key)
        req = requests.get(data_url)
        jdata = req.json()

        a = jdata["artist"]
        stats = a["stats"]
        # tags = [t['name'] for t in a['tags']['tag']]
        # url = a['url']

        data.append(
            {
                "plays": stats["playcount"],
                "listeners": stats["listeners"],
                "network.id": artist,
                "timestamp": datetime(*time.gmtime()[:6]),
            }
        )

    return prepare_data(data)