Пример #1
0
def initializeCampaign(request, campaign_id):
    try:
        campaign = Campaign.objects.get(pk=campaign_id)
        campaign.facebook_comments = 0
        campaign.facebook_likes = 0
        campaign.facebook_shares = 0
        campaign.facebook_total = 0
        campaign.yt_like_count = 0
        campaign.yt_dislike_count = 0
        campaign.yt_fav_count = 0
        campaign.yt_comment_count = 0
        campaign.yt_view_count = 0
        campaign.tweets = 0
        campaign.g_plus_one = 0
        campaign.g_replies = 0
        campaign.g_reshares = 0
        campaign.linkedin = 0
        campaign.stumble = 0
        campaign.pins = 0
        campaign.diggs = 0
        campaign.save()
        daily_data = fbDataRequest(url=campaign.url, campaign=campaign)
        daily_data.save()
    except Exception as e:
        print e
    return redirect("fbsharing.views.socialShares", daily_data.id)
Пример #2
0
def displayStats(request, data_id):
    try:
        data = fbDataRequest.objects.get(pk=data_id)
    except Exception as e:
        print e
    facebook = fbDataRequest()
    form = dataForm(instance=facebook)
    return render_to_response(
        "fbsharing/url_form.html", {"form": form, "data": data}, context_instance=RequestContext(request)
    )
Пример #3
0
def displayStats(request, data_id):
    try:
        data = fbDataRequest.objects.get(pk=data_id)
    except Exception as e:
        print e
    facebook = fbDataRequest()
    form = dataForm(instance=facebook)
    return render_to_response('fbsharing/url_form.html', {
        'form': form,
        'data': data
    },
                              context_instance=RequestContext(request))
Пример #4
0
def updateAllCampaigns(request):
    try:
        campaigns = Campaign.objects.filter(current=True)
        # Update all engagement statistics for each current campaign
        for campaign in campaigns:
            daily_data = fbDataRequest(url=campaign.url, campaign=campaign)
            daily_data.save()
            socialShares(daily_data.id)
            youtube(daily_data.id)
    except Exception as e:
        raise e
    return render_to_response('fbsharing/view_campaigns.html',
                              {'campaigns': campaigns},
                              context_instance=RequestContext(request))
Пример #5
0
def updateAllCampaigns(request):
    try:
        campaigns = Campaign.objects.filter(current=True)
        # Update all engagement statistics for each current campaign
        for campaign in campaigns:
            daily_data = fbDataRequest(url=campaign.url, campaign=campaign)
            daily_data.save()
            socialShares(daily_data.id)
            youtube(daily_data.id)
    except Exception as e:
        raise e
    return render_to_response(
        "fbsharing/view_campaigns.html", {"campaigns": campaigns}, context_instance=RequestContext(request)
    )
Пример #6
0
def getFacebookStats(request):
    facebook = fbDataRequest()
    if request.method == "POST":
        if linkValid(request.POST["url"]):
            form = dataForm(request.POST, instance=facebook)
            if form.is_valid():
                try:
                    facebook = form.save()
                    # return redirect('fbsharing.views.getRecentTweets', facebook.id)
                    callback_url = "http://" + request.META["HTTP_HOST"] + "/fb/betterStats/" + str(facebook.id)
                    return HttpResponseRedirect(
                        REQUEST_TOKEN_URL
                        + "?client_id=%s&client_secret=%s&grant_type=client_credentials&redirect_uri=%s"
                        % (APP_ID, APP_SECRET, callback_url)
                    )
                except Exception as e:
                    print "Data Request object failed to save"
    form = dataForm(instance=facebook)
    return render_to_response("fbsharing/fb_url_form.html", {"form": form}, context_instance=RequestContext(request))
Пример #7
0
def getFacebookStats(request):
    facebook = fbDataRequest()
    if request.method == 'POST':
        if linkValid(request.POST['url']):
            form = dataForm(request.POST, instance=facebook)
            if form.is_valid():
                try:
                    facebook = form.save()
                    # return redirect('fbsharing.views.getRecentTweets', facebook.id)
                    callback_url = 'http://' + request.META[
                        'HTTP_HOST'] + '/fb/betterStats/' + str(facebook.id)
                    return HttpResponseRedirect(
                        REQUEST_TOKEN_URL +
                        '?client_id=%s&client_secret=%s&grant_type=client_credentials&redirect_uri=%s'
                        % (APP_ID, APP_SECRET, callback_url))
                except Exception as e:
                    print "Data Request object failed to save"
    form = dataForm(instance=facebook)
    return render_to_response('fbsharing/fb_url_form.html', {'form': form},
                              context_instance=RequestContext(request))
Пример #8
0
def getFacebookStats(request):
    facebook = fbDataRequest()
    if request.method == "POST":
        if linkValid(request.POST["url"]):
            form = dataForm(request.POST, instance=facebook)
            if form.is_valid():
                try:
                    facebook = form.save()
                    return redirect("fbsharing.views.getBetterFacebookStats", facebook.id)
                    # This callback URL allows facebook to redirect back to our server once OAuth login has been completed
                    # The callback url for the Access Token request must be identical to the one being used here (to request a code to exchange for an access token)
                    callback_url = "http://" + request.META["HTTP_HOST"] + "/fb/betterStats/" + str(facebook.id)
                    return HttpResponseRedirect(
                        REQUEST_TOKEN_URL
                        + "?client_id=%s&client_secret=%s&grant_type=client_credentials&redirect_uri=%s"
                        % (APP_ID, APP_SECRET, callback_url)
                    )
                except Exception as e:
                    print "Data Request object failed to save"
    form = dataForm(instance=facebook)
    return render_to_response("fbsharing/fb_url_form.html", {"form": form}, context_instance=RequestContext(request))
Пример #9
0
def getFacebookStats(request):
    facebook = fbDataRequest()
    if request.method == 'POST':
        if linkValid(request.POST['url']):
            form = dataForm(request.POST, instance=facebook)
            if form.is_valid():
                try:
                    facebook = form.save()
                    return redirect('fbsharing.views.getBetterFacebookStats',
                                    facebook.id)
                    # This callback URL allows facebook to redirect back to our server once OAuth login has been completed
                    # The callback url for the Access Token request must be identical to the one being used here (to request a code to exchange for an access token)
                    callback_url = 'http://' + request.META[
                        'HTTP_HOST'] + '/fb/betterStats/' + str(facebook.id)
                    return HttpResponseRedirect(
                        REQUEST_TOKEN_URL +
                        '?client_id=%s&client_secret=%s&grant_type=client_credentials&redirect_uri=%s'
                        % (APP_ID, APP_SECRET, callback_url))
                except Exception as e:
                    print "Data Request object failed to save"
    form = dataForm(instance=facebook)
    return render_to_response('fbsharing/fb_url_form.html', {'form': form},
                              context_instance=RequestContext(request))
Пример #10
0
def getDailyStats(daily_id):
    try:
        daily = DailyRun.objects.get(pk=daily_id)
        campaign = daily.current
        data = fbDataRequest(campaign=campaign, url=campaign.url)
    except Exception as e:
        print e
    try:
        consumer = oauth.Consumer(key=TWITTER_CONSUMER_KEY,
                                  secret=TWITTER_CONSUMER_SECRET)
        client = oauth.Client(consumer)
        request_url = TWITTER_SEARCH_URL + data.url
        resp, cont = client.request(request_url, 'GET')
        if resp['status'] == '200':
            new_dic = ast.literal_eval(cont)
            data.tweets = int(new_dic['count']) - campaign.tweets
            campaign.tweets = int(new_dic['count'])
        else:
            print "Twitter API call failed"
    except Exception as e:
        print e
    try:
        content = urllib.urlopen(
            "http://www.stumbleupon.com/services/1.01/badge.getinfo?url=" +
            data.url)
        cont_data = json.load(content)
        if cont_data['result']['in_index'] == False:
            data.stumble = 0
        else:
            data.stumble = int(cont_data['result']['views']) - campaign.stumble
            campaign.stumble = int(cont_data['result']['views'])
    except Exception as e:
        print e
    try:
        content = urllib.urlopen(
            "http://api.pinterest.com/v1/urls/count.json?callback=&url=" +
            data.url).read()
        new_dic = ast.literal_eval(content)
        data.pins = int(new_dic['count']) - campaign.pins
        campaign.pins = int(new_dic['count'])
    except Exception as e:
        print e
    try:
        content = urllib.urlopen(
            "http://www.linkedin.com/countserv/count/share?url=" + data.url +
            "&format=json").read()
        new_dic = ast.literal_eval(content)
        data.linkedin = int(new_dic['count']) - campaign.linkedin
        campaign.linkedin = int(new_dic['count'])
    except Exception as e:
        print e
    try:
        request_url = GOOG_ACT_SEARCH + "?query=" + convertString(
            data.url) + "&key=" + API_KEY
        content = urllib.urlopen(request_url).read()
        new_dic = ast.literal_eval(content)
        for item in new_dic['items']:
            if makeHttp(data_id) == item['object']['attachments'][0]['url']:
                activity_id = item['id']
                request_url2 = GOOG_ACT_SEARCH + "/" + activity_id + "?key=" + API_KEY
                content2 = urllib.urlopen(request_url2).read()
                dic = ast.literal_eval(content2)
                data.g_reshares = int(dic['object']['resharers']
                                      ['totalItems']) - campaign.g_reshares
                data.g_plus_one = int(dic['object']['plusoners']
                                      ['totalItems']) - campaign.g_plus_one
                data.g_replies = int(dic['object']['replies']
                                     ['totalItems']) - campaign.g_replies
                campaign.g_reshares = int(
                    dic['object']['resharers']['totalItems'])
                campaign.g_plus_one = int(
                    dic['object']['plusoners']['totalItems'])
                campaign.g_replies = int(
                    dic['object']['replies']['totalItems'])
    except Exception as e:
        print e
    try:
        my_url = STATISTICS_URL + "?id=" + getVideoID(
            data.url
        ) + "&part=statistics&field=monetizationDetails" + "%" + "2Cstatistics&key=" + API_KEY
        r = urllib2.urlopen(my_url)
        response = ast.literal_eval(r.read())
        data.yt_comment_count = int(
            response['items'][0]['statistics']
            ['commentCount']) - campaign.yt_comment_count
        data.yt_view_count = int(response['items'][0]['statistics']
                                 ['viewCount']) - campaign.yt_view_count
        data.yt_fav_count = int(response['items'][0]['statistics']
                                ['favoriteCount']) - campaign.yt_fav_count
        data.yt_dislike_count = int(
            response['items'][0]['statistics']
            ['dislikeCount']) - campaign.yt_dislike_count
        data.yt_like_count = int(response['items'][0]['statistics']
                                 ['likeCount']) - campaign.yt_like_count
        campaign.yt_comment_count = int(
            response['items'][0]['statistics']['commentCount'])
        campaign.yt_view_count = int(
            response['items'][0]['statistics']['viewCount'])
        campaign.yt_fav_count = int(
            response['items'][0]['statistics']['favoriteCount'])
        campaign.yt_dislike_count = int(
            response['items'][0]['statistics']['dislikeCount'])
        campaign.yt_like_count = int(
            response['items'][0]['statistics']['likeCount'])
    except Exception as e:
        print e
    try:
        data.save()
        campaign.save()
    except Exception as e:
        print e
    callback_url = 'http://' + request.META[
        'HTTP_HOST'] + '/fb/dailyFBStats/' + str(daily.id) + "/" + str(data.id)
    return HttpResponseRedirect(
        REQUEST_TOKEN_URL +
        '?client_id=%s&client_secret=%s&grant_type=client_credentials&redirect_uri=%s'
        % (APP_ID, APP_SECRET, callback_url))
Пример #11
0
def getDailyStats(daily_id):
    try:
        daily = DailyRun.objects.get(pk=daily_id)
        campaign = daily.current
        data = fbDataRequest(campaign=campaign, url=campaign.url)
    except Exception as e:
        print e
    try:
        consumer = oauth.Consumer(key=TWITTER_CONSUMER_KEY, secret=TWITTER_CONSUMER_SECRET)
        client = oauth.Client(consumer)
        request_url = TWITTER_SEARCH_URL + data.url
        resp, cont = client.request(request_url, "GET")
        if resp["status"] == "200":
            new_dic = ast.literal_eval(cont)
            data.tweets = int(new_dic["count"]) - campaign.tweets
            campaign.tweets = int(new_dic["count"])
        else:
            print "Twitter API call failed"
    except Exception as e:
        print e
    try:
        content = urllib.urlopen("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=" + data.url)
        cont_data = json.load(content)
        if cont_data["result"]["in_index"] == False:
            data.stumble = 0
        else:
            data.stumble = int(cont_data["result"]["views"]) - campaign.stumble
            campaign.stumble = int(cont_data["result"]["views"])
    except Exception as e:
        print e
    try:
        content = urllib.urlopen("http://api.pinterest.com/v1/urls/count.json?callback=&url=" + data.url).read()
        new_dic = ast.literal_eval(content)
        data.pins = int(new_dic["count"]) - campaign.pins
        campaign.pins = int(new_dic["count"])
    except Exception as e:
        print e
    try:
        content = urllib.urlopen(
            "http://www.linkedin.com/countserv/count/share?url=" + data.url + "&format=json"
        ).read()
        new_dic = ast.literal_eval(content)
        data.linkedin = int(new_dic["count"]) - campaign.linkedin
        campaign.linkedin = int(new_dic["count"])
    except Exception as e:
        print e
    try:
        request_url = GOOG_ACT_SEARCH + "?query=" + convertString(data.url) + "&key=" + API_KEY
        content = urllib.urlopen(request_url).read()
        new_dic = ast.literal_eval(content)
        for item in new_dic["items"]:
            if makeHttp(data_id) == item["object"]["attachments"][0]["url"]:
                activity_id = item["id"]
                request_url2 = GOOG_ACT_SEARCH + "/" + activity_id + "?key=" + API_KEY
                content2 = urllib.urlopen(request_url2).read()
                dic = ast.literal_eval(content2)
                data.g_reshares = int(dic["object"]["resharers"]["totalItems"]) - campaign.g_reshares
                data.g_plus_one = int(dic["object"]["plusoners"]["totalItems"]) - campaign.g_plus_one
                data.g_replies = int(dic["object"]["replies"]["totalItems"]) - campaign.g_replies
                campaign.g_reshares = int(dic["object"]["resharers"]["totalItems"])
                campaign.g_plus_one = int(dic["object"]["plusoners"]["totalItems"])
                campaign.g_replies = int(dic["object"]["replies"]["totalItems"])
    except Exception as e:
        print e
    try:
        my_url = (
            STATISTICS_URL
            + "?id="
            + getVideoID(data.url)
            + "&part=statistics&field=monetizationDetails"
            + "%"
            + "2Cstatistics&key="
            + API_KEY
        )
        r = urllib2.urlopen(my_url)
        response = ast.literal_eval(r.read())
        data.yt_comment_count = int(response["items"][0]["statistics"]["commentCount"]) - campaign.yt_comment_count
        data.yt_view_count = int(response["items"][0]["statistics"]["viewCount"]) - campaign.yt_view_count
        data.yt_fav_count = int(response["items"][0]["statistics"]["favoriteCount"]) - campaign.yt_fav_count
        data.yt_dislike_count = int(response["items"][0]["statistics"]["dislikeCount"]) - campaign.yt_dislike_count
        data.yt_like_count = int(response["items"][0]["statistics"]["likeCount"]) - campaign.yt_like_count
        campaign.yt_comment_count = int(response["items"][0]["statistics"]["commentCount"])
        campaign.yt_view_count = int(response["items"][0]["statistics"]["viewCount"])
        campaign.yt_fav_count = int(response["items"][0]["statistics"]["favoriteCount"])
        campaign.yt_dislike_count = int(response["items"][0]["statistics"]["dislikeCount"])
        campaign.yt_like_count = int(response["items"][0]["statistics"]["likeCount"])
    except Exception as e:
        print e
    try:
        data.save()
        campaign.save()
    except Exception as e:
        print e
    callback_url = "http://" + request.META["HTTP_HOST"] + "/fb/dailyFBStats/" + str(daily.id) + "/" + str(data.id)
    return HttpResponseRedirect(
        REQUEST_TOKEN_URL
        + "?client_id=%s&client_secret=%s&grant_type=client_credentials&redirect_uri=%s"
        % (APP_ID, APP_SECRET, callback_url)
    )