Ejemplo n.º 1
0
def main(argv):

  # Step 1. Get an analytics service object.
  service = hello_analytics_api_v3_auth.initialize_service()
  accounts = service.management().accounts().list().execute()
  ## use this line to use segments segment_id = 'gaid::'+raw_input('Please enter your preferred segment id. If you want no segments, enter -1 ')
  for accountProfiles in range (12):
    for x in range (countWebProperties(service,accounts,accountProfiles)):
      time.sleep(0.1)
      try:
        # Step 2. Get the user's first profile ID.
        profile_id = get_first_profile_id(service,accounts,accountProfiles,x)
        if profile_id:
          # Step 3. Query the Core Reporting API.
          results = get_results(service, profile_id)
          # Step 4. Output the results.
          print_results(results)
      except TypeError, error:
        # Handle errors in constructing a query.
        print ('There was an error in constructing your query : %s' % error)

      except HttpError, error:
        # Handle API errors.
        print ('Arg, there was an API error : %s : %s' %
               (error.resp.status, error._get_reason()))

      except AccessTokenRefreshError:
        # Handle Auth errors.
        print ('The credentials have been revoked or expired, please re-run '
               'the application to re-authorize')
Ejemplo n.º 2
0
def main(argv):
    # Initialize the Analytics Service Object
    analytics_service_object = hello_analytics_api_v3_auth.initialize_service()
    
    results = get_results(analytics_service_object, hello_analytics_api_v3_auth.PROFILE_ID)
    
    sort_results(results, NUM_FIELDS)
Ejemplo n.º 3
0
def main(argv):
    # Step 1. Get an analytics service object.
    service = hello_analytics_api_v3_auth.initialize_service()
    for sites in range(12):
        try:
            # Step 2. Get the user's first profile ID.
            profile_id = get_first_profile_id(service, sites)
            print "profileID \t%s" % str(profile_id)

            if profile_id:
                # Step 3. Query the Core Reporting API.
                results = get_results(service, profile_id)
                #print "I got the results"

                # Step 4. Output the results.
                print_results(results)
            #print "I printed the results"

        except TypeError, error:
            # Handle errors in constructing a query.
            print('There was an error in constructing your query : %s' % error)

        except HttpError, error:
            # Handle API errors.
            print('Arg, there was an API error : %s : %s' %
                  (error.resp.status, error._get_reason()))
Ejemplo n.º 4
0
def main(argv):
  # Initialize the Analytics Service Object
  service = hello_analytics_api_v3_auth.initialize_service()

  try:
    # Query APIs, print results
    profile_id = get_first_profile_id(service)

    if profile_id:
      results = get_results(service, profile_id)
      print_results(results)

  except TypeError:
    # Handle errors in constructing a query.
    print ('There was an error in constructing your query : %s' % error)

  except HttpError:
    # Handle API errors.
    print ('Arg, there was an API error : %s : %s' %
           (error.resp.status, error._get_reason()))

  except AccessTokenRefreshError:
    # Handle Auth errors.
    print ('The credentials have been revoked or expired, please re-run '
           'the application to re-authorize')
def main(argv):
  # Step 1. Get an analytics service object.
  service = hello_analytics_api_v3_auth.initialize_service()
  for sites in range (12):
    try:
      # Step 2. Get the user's first profile ID.
      profile_id = get_first_profile_id(service,sites)
      print "profileID \t%s" %str(profile_id)

      if profile_id:
        # Step 3. Query the Core Reporting API.
        results = get_results(service, profile_id)
        #print "I got the results"

        # Step 4. Output the results.
        print_results(results)
       #print "I printed the results"

    except TypeError, error:
      # Handle errors in constructing a query.
      print ('There was an error in constructing your query : %s' % error)

    except HttpError, error:
      # Handle API errors.
      print ('Arg, there was an API error : %s : %s' %
             (error.resp.status, error._get_reason()))
Ejemplo n.º 6
0
def main(argv):
    # Initialize the Analytics Service Object
    analytics_service_object = hello_analytics_api_v3_auth.initialize_service()
    
    try:
        #List the accounts
        accounts_response = analytics_service_object.management().accounts().list().execute()

    except TypeError, error:
        # Handle errors in constructing a query.
        print ('There was an error in constructing your accounts query : %s' % error)
Ejemplo n.º 7
0
def main(argv):

    # Step 1. Get an analytics service object.
    service = hello_analytics_api_v3_auth.initialize_service()

    accounts = service.management().accounts().list().execute()
    # accounts is a dictionary that includes some administrative
    # info such as username and email (in this case thehutinsight), but also includes a mapping
    # of 'items' to a list of dictionaries. The list has an entry for
    # each website in the users analytics. That entry is a dictionary mapping
    # a set of variables including 'name' to e.g. 'www.thehut.com' and 'id' to e.g. 59323
    counter = 0
    segmentName = raw_input("Please Enter your preferred Segment Name (Hit Enter for All Visits)\n")
    try:
        segment_id = "gaid::" + segmentIds.segments_Dictionary[segmentName]
    except:
        print "Oh dear, That Segment doesn't exist. Please try again or hit enter for no segments"
        segment_id = "gaid::" + segmentIds.segments_Dictionary[segmentName]

    for accountProfiles in range(13):
        for x in range(countWebProperties(service, accounts, accountProfiles)):
            time.sleep(0.3)
            try:
                # Step 2. Get the user's first profile ID.
                helperList = get_first_profile_id(service, accounts, accountProfiles, x)
                profile_id = helperList[0]

                if profile_id:
                    try:
                        activeWebsites[helperList[1]]
                        # Step 3. Query the Core Reporting API.
                        results = get_results(service, profile_id, segment_id)
                    except (KeyError):
                        results = None

                    # Step 4. Output the results.
                    print_results(results, counter)
                    if results:
                        counter += 1
                # print "I printed the results"

            except TypeError, error:
                # Handle errors in constructing a query.
                print ("There was an error in constructing your query : %s" % error)

            except HttpError, error:
                # Handle API errors.
                print ("Arg, there was an API error : %s : %s" % (error.resp.status, error._get_reason()))

            except AccessTokenRefreshError:
                # Handle Auth errors.
                print ("The credentials have been revoked or expired, please re-run " "the application to re-authorize")
Ejemplo n.º 8
0
def mainHelper(argv, date1, dimensionString, metricString, myNewFile,
               segment_id_list):
    # Step 1. Get an analytics service object.
    service = hello_analytics_api_v3_auth.initialize_service()
    accounts = service.management().accounts().list().execute()
    #accounts is a dictionary that includes some administrative
    #info such as username and email (in this case thehutinsight), but also includes a mapping
    #of 'items' to a list of dictionaries. The list has an entry for
    #each website in the users analytics. That entry is a dictionary mapping
    #a set of variables including 'name' to e.g. 'www.thehut.com' and 'id' to e.g. 59323
    for accountProfiles in range(13):
        for x in range(countWebProperties(service, accounts, accountProfiles)):
            time.sleep(0.3)
            try:
                # Step 2. Get the user's first profile ID.
                helperList = get_first_profile_id(service, accounts,
                                                  accountProfiles, x)
                profile_id = helperList[0]

                if profile_id:
                    try:
                        activeWebsites[helperList[1]]
                        # Step 3. Query the Core Reporting API.
                        results = get_results(service, profile_id,
                                              segment_id_list[0], date1, date1,
                                              dimensionString, metricString)
                    except (KeyError):
                        results = None

                    # Step 4. Output the results.


##          print_results(results,counter,dimensionList, metricList,myNewFile)
##          print "I printed the results"
##          print counter

            except TypeError, error:
                # Handle errors in constructing a query.
                print('There was an error in constructing your query : %s' %
                      error)

            except HttpError, error:
                # Handle API errors.
                print('Arg, there was an API error : %s : %s' %
                      (error.resp.status, error._get_reason()))

            except AccessTokenRefreshError:
                # Handle Auth errors.
                print(
                    'The credentials have been revoked or expired, please re-run '
                    'the application to re-authorize')
def query_to_results(query_object):
    service = hello_analytics_api_v3_auth.initialize_service()
    accounts = service.management().accounts().list().execute()
    results_list = []
    parameters = extract_arguments(query_object)
    for site in parameters['profiles']:
        for segment in parameters['segments']:
            for dates in range (len(parameters['dates'])):
                results_list.append(get_results(service,site,segment,parameters['dates'][dates]['start'],parameters['dates'][dates]['end'],parameters['dimensions'],parameters['metrics']))
                time.sleep(0.5)
            time.sleep(0.1)
        time.sleep(0.1)
    time.sleep(0.1)
    return results_list
Ejemplo n.º 10
0
def main(argv):
  service = hello_analytics_api_v3_auth.initialize_service()

  try:
    # Query APIs, print results
    profile_id = get_first_profile_id(service)

    if profile_id:
      results = get_results(service, profile_id)
      print_results(results)

  except TypeError, error:
    # Handle errors in constructing a query.
    print ('There was an error in constructing your query : %s' % error)
Ejemplo n.º 11
0
def main(argv):
    funDict = {"": "-1", "UK": "470502913"}

    # Step 1. Get an analytics service object.
    service = hello_analytics_api_v3_auth.initialize_service()
    accounts = service.management().accounts().list().execute()
    segment_id = "gaid::-1"
    try:
        profiles = service.management().segments().list().execute()

    except TypeError, error:
        # Handle errors in constructing a query.
        print("There was an error in constructing your query : %s" % error)
        profiles = {"items": "hi"}
def query_to_results(query_object):
    service = hello_analytics_api_v3_auth.initialize_service()
    accounts = service.management().accounts().list().execute()
    results_list = []
    parameters = extract_arguments(query_object)
    for site in parameters['profiles']:
        for segment in parameters['segments']:
            for dates in range (len(parameters['dates'])):
                results_list.append(get_results(service,site,segment,parameters['dates'][dates]['start'],parameters['dates'][dates]['end'],parameters['dimensions'],parameters['metrics']))
                time.sleep(0.5)
            time.sleep(0.1)
        time.sleep(0.1)
    time.sleep(0.1)
    return results_list
Ejemplo n.º 13
0
def main(argv):
    # Initialize the Analytics Service Object
    analytics_service_object = hello_analytics_api_v3_auth.initialize_service()
    
    WEB_PROPERTY_ID = hello_analytics_api_v3_auth.WEB_PROPERTY_ID
    
    try:
        profiles_response = analytics_service_object.management().profiles().list(  #Note that you needed to edit this to profiles_response from the docs
            accountId=WEB_PROPERTY_ID.split('-')[1],
            webPropertyId=WEB_PROPERTY_ID).execute()
        
    except TypeError, error:
        # Handle errors in constructing a query.
        print ('There was an error in constructing your profiles query : %s' % error)
Ejemplo n.º 14
0
def main(argv):
  service = hello_analytics_api_v3_auth.initialize_service()
  
  accounts = service.management().accounts().list().execute()
  counter = 0
  segmentName = raw_input('Please Enter your preferred Segment Name (Hit Enter for All Visits)\n')
  try:
    segment_id = 'gaid::'+segmentIds.segments_Dictionary[segmentName]
  except:
    print "Oh dear, That Segment doesn't exist. Please try again or hit enter for no segments"
    segment_id = 'gaid::'+segmentIds.segments_Dictionary[segmentName]
 
  for accountProfiles in range (20):
    for x in range (countWebProperties(service,accounts,accountProfiles)):
      time.sleep(0.4)
      try:
        # Step 2. Get the user's first profile ID.
        helperList = get_first_profile_id(service,accounts,accountProfiles,x)
        print helperList
        profile_id = helperList[0]

        if profile_id:
          try:
            activeWebsites[helperList[1]]
          # Step 3. Query the Core Reporting API.
            results = get_results(service, profile_id, segment_id)
          except(KeyError):
            results = None

          # Step 4. Output the results.
          print_results(results,counter)
          if results:
            counter += 1
         #print "I printed the results"
              
      except TypeError, error:
        # Handle errors in constructing a query.
        print ('There was an error in constructing your query : %s' % error)

      except HttpError, error:
        # Handle API errors.
        print ('Arg, there was an API error : %s : %s' %
               (error.resp.status, error._get_reason()))

      except AccessTokenRefreshError:
        # Handle Auth errors.
        print ('The credentials have been revoked or expired, please re-run '
               'the application to re-authorize')
Ejemplo n.º 15
0
def main(argv):
  # Initialize the Analytics Service Object
  service = hello_analytics_api_v3_auth.initialize_service()

  try:
    # Query APIs, print results
    profile_id = get_first_profile_id(service)
    
    if profile_id:
      results = get_results(service, profile_id)
      
      print_results(results) #This line throws the exception
  
  except TypeError, error:
    # Handle errors in constructing a query.
    print ('There was an error in constructing your 1st query : %s' % error)
Ejemplo n.º 16
0
def mainHelper(argv,date1, date2, dimensionString, metricString, dimensionList, metricList,myNewFile,segment_id):
  # Step 1. Get an analytics service object.
  service = hello_analytics_api_v3_auth.initialize_service()
  accounts = service.management().accounts().list().execute()
  #accounts is a dictionary that includes some administrative
  #info such as username and email (in this case thehutinsight), but also includes a mapping
  #of 'items' to a list of dictionaries. The list has an entry for
  #each website in the users analytics. That entry is a dictionary mapping
  #a set of variables including 'name' to e.g. 'www.thehut.com' and 'id' to e.g. 59323
  counter = 0
  for accountProfiles in range (13):
    for x in range (countWebProperties(service,accounts,accountProfiles)):
      time.sleep(0.3)
      try:
        # Step 2. Get the user's first profile ID.
        helperList = get_first_profile_id(service,accounts,accountProfiles,x)
        profile_id = helperList[0]

        if profile_id:
          try:
            activeWebsites[helperList[1]]
          # Step 3. Query the Core Reporting API.
            results = get_results(service, profile_id, segment_id, date1, date2, dimensionString, metricString)
          except(KeyError):
            results = None

          # Step 4. Output the results.
          print_results(results,counter,dimensionList, metricList,myNewFile)
          if results:
            counter += 1
         #print "I printed the results"
              
      except (TypeError):
        # Handle errors in constructing a query.
        print ('There was an error in constructing your query : %s' % error)

      except (HttpError):
        # Handle API errors.
        print ('Arg, there was an API error : %s : %s' %
               (error.resp.status, error._get_reason()))

      except (AccessTokenRefreshError):
        # Handle Auth errors.
        print ('The credentials have been revoked or expired, please re-run '
               'the application to re-authorize')
Ejemplo n.º 17
0
def main(argv):
  # Step 1. Get an analytics service object.
  service = hello_analytics_api_v3_auth.initialize_service()

  try:
    # Step 2. Get the user's first profile ID.
    profile_id = get_first_profile_id(service)

    if profile_id:
      # Step 3. Query the Core Reporting API.
      results = get_results(service, profile_id)

      # Step 4. Output the results.
      print_results(results)

  except TypeError, error:
    # Handle errors in constructing a query.
    print ('There was an error in constructing your query : %s' % error)
Ejemplo n.º 18
0
def main(argv):
  # Step 1. Get an analytics service object.
  service = hello_analytics_api_v3_auth.initialize_service()

  try:
    # Step 2. Get the user's first profile ID.
    profile_id = get_first_profile_id(service)

    if profile_id:
      # Step 3. Query the Core Reporting API.
      results = get_results(service, profile_id)

      # Step 4. Output the results.
      print_results(results)

  except TypeError, error:
    # Handle errors in constructing a query.
    print ('There was an error in constructing your query : %s' % error)
def main(argv):

  ## print x
  ##print "Hey-ho merry-o ring a ding a dillo what the chuff"
  # Step 1. Get an analytics service object.
  service = hello_analytics_api_v3_auth.initialize_service()
  accounts = service.management().accounts().list().execute()
  segment_id = 'gaid::-1'
##  segments = service.management().segments().list().execute()
##  print segments
  for accountProfiles in range (12):
    for x in range (countWebProperties(service,accounts,accountProfiles)):
      time.sleep(0.1)
      try:
        # Step 2. Get the user's first profile ID.
        profile_id = get_first_profile_id(service,accounts,accountProfiles,x)
##        print "profileID \t%s" %str(profile_id)

        if profile_id:
          # Step 3. Query the Core Reporting API.
          results = get_results(service, profile_id, segment_id)
          #print "I got the results"

          # Step 4. Output the results.
          print_results(results)
         #print "I printed the results"

      except TypeError, error:
        # Handle errors in constructing a query.
        print ('There was an error in constructing your query : %s' % error)

      except HttpError, error:
        # Handle API errors.
        print ('Arg, there was an API error : %s : %s' %
               (error.resp.status, error._get_reason()))

      except AccessTokenRefreshError:
        # Handle Auth errors.
        print ('The credentials have been revoked or expired, please re-run '
               'the application to re-authorize')
def main(curr_day):
    # Step 1. Get an analytics service object.
    service = hello_analytics_api_v3_auth.initialize_service()
    #logfile = open("log.log",'wb')
    #accounts_map = {
    #    "Daily Life" : "22700242", #AKA Fairfax Media - Metro
    #    "Drive" : "22516094",
    #    "TP New Car Showroom" : "2019139",
    #    "Kidspot" : "225257",
    #    "Living Social" : "3767395",
    #    "Mazda" : "10349309",
    #    }

    ##accounts = service.management().accounts().list().execute()

    #for account_name,account_id in accounts_map.iteritems():
    #    logfile.write(str('\n'+account_name+'\n'))
    #    #Grab web properties and their IDS
    #    logfile.write("\nWEB PROPERTIES\n")
    #    webproperties = service.management().webproperties().list(accountId=account_id).execute()

    #    for web_p in webproperties.get('items'):
    #        logfile.write('\n'+str(web_p))
    #        #obtain profile ID
    #        profiles = service.management().profiles().list(
    #        accountId=account_id,
    #        webPropertyId=web_p['id']).execute()
    #        try:
    #            for profile in profiles['items']:
    #                logfile.write("\nPROFILES\n")
    #                logfile.write('\n'+str(profile))
    #        except:
    #            continue
    #        #logfile.writelines(profiles)

    #logfile.close()
    profile_map = {
        "Daily Life": "54624166",  #AKA Fairfax Media - Metro
        #        "Drive" : "44394715",
        "TP New Car Showroom": "69339994",
        "Kidspot": "299451",
        "Living Social": "85692242",
        #        "Mazda" : "10349309",
        "Ausvance": "65347538",
    }
    for profile_name, profile_id in profile_map.iteritems():
        writer = open(profile_name + '.txt', 'wb')
        try:
            print("Pulling results for %s" % profile_name)
            results = get_results(service, profile_id, curr_day)
            #DO SOMETHING WITH RESULTS
            upload_rows = []
            if results:
                print("Processing Results")
                for row in results['rows']:
                    print(row)
                    try:
                        split_ad_content = str(row[0]).split('_')
                        pub_id = split_ad_content[2]
                        source_id = split_ad_content[3]
                        sub_id = split_ad_content[4]
                        tier = split_ad_content[0].replace('DB-', '')
                        product = split_ad_content[1]

                    except:
                        pub_id = ''
                        source_id = ''
                        sub_id = ''
                        tier = ''
                        product = ''

                    new_row = [
                        curr_day, profile_name,
                        str(row[0]),
                        int(row[1]),
                        int(row[2]),
                        float(row[3]),
                        int(row[4]),
                        int(row[5]),
                        float(row[6]),
                        float(row[7]),
                        float(row[8]), tier, product, pub_id, source_id, sub_id
                    ]
                    upload_rows.append(new_row)

                upload_data(upload_rows, curr_day, profile_name)
        except:

            error = traceback.format_exc()
            mail(error, profile_name)
            continue
Ejemplo n.º 21
0
import Analytics_Methods as AM
import hello_analytics_api_v3_auth
from apiclient.errors import HttpError
from oauth2client.client import AccessTokenRefreshError
import datetime
import segmentIds as si
import dimensions_and_metrics
import collectArguments as ca
import analytics_ids as ai
import site_to_dictionary as std
import datetime
from datetime import timedelta
from datetime import date

service = hello_analytics_api_v3_auth.initialize_service()
accounts = service.management().accounts().list().execute()
now = datetime.datetime.now()
today = now.strftime('%Y-%m-%d')

profile_ids = AM.get_profile_ids()
site_profiles = AM.get_site_profiles()
account_items = AM.get_account_items()
webproperties = AM.get_webproperties()
account_ids_to_websites = AM.get_account_ids_to_websites()
account_ids_to_website_ids = AM.get_account_ids_to_website_ids()
all_profiles = AM.get_profile_list()
site_name_to_true_webPropertyId = AM.get_site_name_to_true_webPropertyId()
get_site_name_to_true_webPropertyId = AM.get_site_name_to_true_webPropertyId()
dates = AM.get_dates()
final_results = AM.get_final_results()
#write_to_file()
Ejemplo n.º 22
0
import Analytics_Methods as AM
import hello_analytics_api_v3_auth
from apiclient.errors import HttpError
from oauth2client.client import AccessTokenRefreshError
import datetime
import segmentIds as si
import dimensions_and_metrics
import collectArguments as ca
import analytics_ids as ai
import site_to_dictionary as std
import datetime
from datetime import timedelta
from datetime import date

service = hello_analytics_api_v3_auth.initialize_service()
accounts = service.management().accounts().list().execute()
now = datetime.datetime.now()
today = now.strftime('%Y-%m-%d')



profile_ids = AM.get_profile_ids()
site_profiles = AM.get_site_profiles()
account_items = AM.get_account_items()
webproperties = AM.get_webproperties()
account_ids_to_websites = AM.get_account_ids_to_websites()
account_ids_to_website_ids = AM.get_account_ids_to_website_ids()
all_profiles = AM.get_profile_list()
site_name_to_true_webPropertyId = AM.get_site_name_to_true_webPropertyId()
get_site_name_to_true_webPropertyId = AM.get_site_name_to_true_webPropertyId()
dates = AM.get_dates()
def main(curr_day):
    # Step 1. Get an analytics service object.
    service = hello_analytics_api_v3_auth.initialize_service()
    #logfile = open("log.log",'wb')
    #accounts_map = { 
    #    "Daily Life" : "22700242", #AKA Fairfax Media - Metro
    #    "Drive" : "22516094", 
    #    "TP New Car Showroom" : "2019139", 
    #    "Kidspot" : "225257", 
    #    "Living Social" : "3767395", 
    #    "Mazda" : "10349309", 
    #    } 
    
    ##accounts = service.management().accounts().list().execute()

    #for account_name,account_id in accounts_map.iteritems():
    #    logfile.write(str('\n'+account_name+'\n'))
    #    #Grab web properties and their IDS
    #    logfile.write("\nWEB PROPERTIES\n")
    #    webproperties = service.management().webproperties().list(accountId=account_id).execute()

    #    for web_p in webproperties.get('items'):
    #        logfile.write('\n'+str(web_p))
    #        #obtain profile ID
    #        profiles = service.management().profiles().list(
    #        accountId=account_id,
    #        webPropertyId=web_p['id']).execute()
    #        try:
    #            for profile in profiles['items']:
    #                logfile.write("\nPROFILES\n")
    #                logfile.write('\n'+str(profile))
    #        except:
    #            continue
    #        #logfile.writelines(profiles)

    #logfile.close()
    profile_map = {
        "Daily Life" : "54624166", #AKA Fairfax Media - Metro
#        "Drive" : "44394715", 
        "TP New Car Showroom" : "69339994", 
        "Kidspot" : "299451", 
        "Living Social" : "85692242", 
#        "Mazda" : "10349309", 
	"Ausvance" : "65347538",
        } 
    for profile_name, profile_id in profile_map.iteritems():
        writer = open(profile_name+'.txt','wb')
        try:
            print("Pulling results for %s"%profile_name)
            results = get_results(service, profile_id, curr_day)
            #DO SOMETHING WITH RESULTS
            upload_rows = []
            if results:
                print("Processing Results")
                for row in results['rows']:
                    print(row)
                    try:
                        split_ad_content = str(row[0]).split('_')
                        pub_id=split_ad_content[2]
                        source_id = split_ad_content[3]
                        sub_id = split_ad_content[4]
                        tier = split_ad_content[0].replace('DB-','')
                        product = split_ad_content[1]
                        
                    except:
                        pub_id=''
                        source_id=''
                        sub_id=''
                        tier=''
                        product=''

                    new_row = [curr_day,profile_name,str(row[0]),int(row[1]),int(row[2]),float(row[3]),int(row[4]),int(row[5]),float(row[6]),float(row[7]),float(row[8]),tier,product,pub_id,source_id,sub_id ]
                    upload_rows.append(new_row)

                upload_data(upload_rows,curr_day,profile_name)
        except:

            error = traceback.format_exc()
            mail(error,profile_name)
            continue