Beispiel #1
0
 for post in posts['data']:
     var1 = post['name']
     var2 = post['period']
     var3 = post['title']
     var4 = post['description']
     var5 = post['id']
     for value in post['values']:
         try:
             var20 = value['value']['video play']
         except:
             var20 = 0
         try:
             var21 = value['value']['other clicks']
         except:
             var21 = 0
         try:
             var22 = value['value']['photo view']
         except:
             var22 = 0
         try:
             var23 = value['value']['link clicks']
         except:
             var23 = 0
         try:
             var24 = value['value']['button clicks']
         except:
             var24 = 0
         var25 = value['end_time'].replace('T07:00:00+0000', '')
         Functions.WriteFile(FileName, str(item), var1, var2, var3, var4,
                             var5, var20, var21, var22, var23, var24, var25)
         #PrintValues(user,var1,var2,var3,var4,var5,var20,var21,var22,var23,var24,var25,var26,var27,var28)
Beispiel #2
0
import csv, facebook, datetime, os, sys, pyodbc
import Connect  #Import connection file
from FacebookInsights import Functions  #Import Functions for creating file
from DatabaseSyncs import DBFunctions as dbf

FileName = Connect.FBPath + "FansByCountry.txt"

try:
    os.remove(FileName)
except OSError:
    pass

daterange = datetime.datetime.now() - datetime.timedelta(days=60)
graph = facebook.GraphAPI(Connect.FACEBOOK_USER_TOKEN)

for item in dbf.FacebookList:
    profile = graph.get_object(str(item))
    posts = graph.get_connections(
        profile['id'], 'insights/page_fans_country?since=%s' % daterange)

    if not posts['data']:
        pass
    else:
        for post in posts['data']:
            for entry in post['values']:
                for key, value in entry['value'].items():
                    Functions.WriteFile(
                        FileName, str(item), post['name'], post['period'],
                        post['title'], post['description'], post['id'], key,
                        value, entry['end_time'].replace('T07:00:00+0000', ''))
                    #PrintValues(user,post['name'],post['period'],post['title'],post['description'],post['id'],key,value,entry['end_time'])
Beispiel #3
0
 try:
     var35 = value['value']['U.18-24']
 except:
     var35 = 0
 try:
     var36 = value['value']['U.25-34']
 except:
     var36 = 0
 try:
     var37 = value['value']['U.35-44']
 except:
     var37 = 0
 try:
     var38 = value['value']['U.45-54']
 except:
     var38 = 0
 try:
     var39 = value['value']['U.55-64']
 except:
     var39 = 0
 try:
     var40 = value['value']['U.65+']
 except:
     var40 = 0
 var41 = value['end_time']
 Functions.WriteFile(FileName, str(item), var1, var2, var3, var4,
                     var5, var20, var21, var22, var23, var24, var25,
                     var26, var27, var28, var29, var30, var31,
                     var32, var33, var34, var35, var36, var37,
                     var38, var39, var40, var41)
 #PrintValues(user,var1,var2,var3,var4,var5,var20,var21,var22,var23,var24,var25,var26,var27,var28)
        try:
            var8 = post['insights']['data'][0]['values'][0]['value'][
                'hide_all_clicks']
            if var8 == "":
                var8 = 0
            else:
                pass
        except:
            var8 = 0
        try:
            var9 = post['insights']['data'][0]['values'][0]['value'][
                'hide_clicks']
            if var9 == "":
                var9 = 0
            else:
                pass
        except:
            var9 = 0
        try:
            var10 = post['insights']['data'][0]['values'][0]['value'][
                'report_spam_clicks']
            if var10 == "":
                var10 = 0
            else:
                pass
        except:
            var10 = 0

        Functions.WriteFile(FileName, str(item), var1, var2, var3, var4, var5,
                            var6, var7, var8, var9, var10)  #Write data to file
 try:
     var6 = post['insights']['data'][0]['name']
 except:
     var6 = 'No Insights Name'
 try:
     var7 = post['insights']['data'][0]['period']
 except:
     var7 = 'No Insights Period'
 try:
     var8 = post['insights']['data'][0]['values'][0]['value'][
         'video play']
 except:
     var8 = 0
 try:
     var9 = post['insights']['data'][0]['values'][0]['value'][
         'other clicks']
 except:
     var9 = 0
 try:
     var10 = post['insights']['data'][0]['values'][0]['value'][
         'photo view']
 except:
     var10 = 0
 try:
     var11 = post['insights']['data'][0]['values'][0]['value'][
         'link clicks']
 except:
     var11 = 0
 Functions.PrintValues(FileName, str(item), var1, var2, var3, var4,
                       var5, var6, var7, var8, var9, var10,
                       var11)  #Write data to file
for item in GoogleIDs:
    dbf.GoogleList.extend(item)

for location in dbf.GoogleList:
    url = (
        "https://mybusiness.googleapis.com/v3/accounts/107604422420814997819/locations/%s/reviews?access_token="
        % location)
    post_url = requests.get(url + access_token)
    posts = post_url.json()

    for post in posts['reviews']:
        try:
            var1 = post['comment'].replace('\n', ' ')
        except:
            var1 = 'No Comment'
        var2 = post['updateTime']
        try:
            var3 = post['reviewId'].replace('\n', ' ')
        except:
            var3 = 'No ReviewID'
        try:
            var4 = post['starRating']
        except:
            var4 = 'No Rating'
        try:
            var5 = post['reviewer']['displayName']
        except:
            var5 = 'No Display Name'
        var6 = post['createTime']
        Functions.WriteFile(FileLocation, location, var1, var2, var3, var4,
                            var5, var6)  #Write data to file
import Connect  #Import connection file
from FacebookInsights import Functions  #Import Functions for creating file
from DatabaseSyncs import DBFunctions as dbf

FileName = Connect.FBPath + "KeyMetricsPost.txt"

try:
    os.remove(FileName)
except OSError:
    pass

daterange = datetime.datetime.now() - datetime.timedelta(days=30)
graph = facebook.GraphAPI(Connect.FACEBOOK_USER_TOKEN)

for item in Connect.UserList:
    profile = graph.get_object(str(item))
    posts = graph.get_connections(
        profile['id'],
        'posts?fields=id,permalink_url,message,type,created_time,insights.metric(post_impressions_unique,post_impressions_organic_unique,post_impressions_paid_unique,post_impressions_organic,post_impressions_paid,post_engaged_users,post_consumptions_unique,post_consumptions,post_negative_feedback,post_impressions_fan,post_impressions_fan_unique,post_impressions_fan_paid,post_impressions_fan_paid_unique,post_engaged_fan,post_video_complete_views_organic_unique,post_video_complete_views_organic,post_video_complete_views_paid_unique,post_video_complete_views_paid,post_video_views_organic_unique,post_video_views_organic,post_video_views_paid_unique,post_video_views_paid,post_video_avg_time_watched,post_video_length).period(lifetime)'
    )

    for post in posts['data']:
        try:
            var1 = post['message']
        except:
            var1 = "No Message"
        for key in post['insights']:
            for entry in post['insights']['data']:
                for value in entry['values']:
                    Functions.WriteFile(FileName,str(item),post['id'],post['permalink_url'],var1,post['type'],post['created_time'],\
                    entry['name'],entry['period'],entry['title'],entry['description'],entry['id'],value['value'])