Esempio n. 1
0
def post_insights_object(video_id, brand_name):
    end_date = datetime.datetime.today().strftime('%Y-%m-%d')
    graph = facebook_graph_object()
    insights = graph.request("319863888091100_" + str(video_id) + "/insights/")
    filepath = 'social_handles_data/' + brand_name + '/' + end_date +'_fb_insights.json'
    if not os.path.isfile(filepath):
        FileUtil.writeJson(filepath, {video_id: {"insights": insights, "meta_info": post_meta_info(video_id)}})
    else:
        data = FileUtil.readJson(filepath)
        if not (video_id in data.keys()):
            data[video_id] = {"insights": insights, "meta_info": post_meta_info(video_id)}
            FileUtil.writeJson(filepath, data)
    return insights
Esempio n. 2
0
def get_youtube_stories(video_ids, start_date, end_date, brand_name):
    youtube_video_ids = get_youtube_video_ids(video_ids)
    insights_file = FileUtil.readJson('social_handles_data/' +brand_name+ '/'+ end_date +'yt_stats.json')

    flag = False
    insight_ids = insights_file.keys()
    for key in youtube_video_ids:
        if str(key) in insight_ids:
            flag = True
    if flag:
        return [insights_file['all_yb'], insights_file['title_info']]
    else:
        return post_insights_object_combined(",".join(youtube_video_ids), brand_name)
Esempio n. 3
0
def post_insights_object(video_id):
    end_date = datetime.datetime.today().strftime('%Y-%m-%d')
    """
    Youtube insights
    """
    google_token = "Bearer ya29.kQIk-bNU4v5AaMwv-cNLLvhtZpSKMs-U_Xr75EwI_oauqqzd20monrJxCVYH9jBicRvX"
    insights = requests.get(
        'https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUCXyq6UjvT4dWjMOOiKuBncA&start-date=' + start_date +'&end-date=' + end_date + '&metrics=views%2Clikes%2Ccomments&filters=video%3D%3D' + video_id + '&key={AIzaSyDT2HJjNdzVRVbxZKWh4PN_AuCxWeqVPsE}&dimensions=video', headers={'Authorization': google_token}
    )
    if not ('rows' in insights.json().keys()):
        google_token = refresh_access_token()
        insights = requests.get(
            'https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUCXyq6UjvT4dWjMOOiKuBncA&start-date='+ start_date +'&end-date=' + end_date + '&metrics=views%2Clikes%2Ccomments&filters=video%3D%3D' + video_id + '&key={AIzaSyDT2HJjNdzVRVbxZKWh4PN_AuCxWeqVPsE}&dimensions=video', headers={'Authorization': 'Bearer '+google_token}
        )
    filepath = 'social_handles_data/'+ end_date +'_yt_insights.json'
    if not os.path.isfile(filepath):
        FileUtil.writeJson(filepath, {video_id: {"insights": insights.json()['rows'], "video_title":post_meta_info(video_id)}})
    else:
        data = FileUtil.readJson(filepath)
        if not (video_id in data.keys()):
            data[video_id] = {"insights": insights.json()['rows'], "video_title":post_meta_info(video_id)}
            FileUtil.writeJson(filepath, data)

    return insights