Beispiel #1
0
    def setUp(self):
        with requests_mock.mock() as m:
            path = os.path.dirname(__file__)
            #read in mock response for Company.GetReportSuites to make tests faster
            with open(path+'/mock_objects/Company.GetReportSuites.json') as get_report_suites_file:
                report_suites = get_report_suites_file.read()

            with open(path+'/mock_objects/Report.GetMetrics.json') as get_metrics_file:
                metrics = get_metrics_file.read()

            with open(path+'/mock_objects/Report.GetElements.json') as get_elements_file:
                elements = get_elements_file.read()

            with open(path+'/mock_objects/Segments.Get.json') as get_segments_file:
                segments = get_segments_file.read()

            #setup mock responses
            m.post('https://api.omniture.com/admin/1.4/rest/?method=Company.GetReportSuites', text=report_suites)
            m.post('https://api.omniture.com/admin/1.4/rest/?method=Report.GetMetrics', text=metrics)
            m.post('https://api.omniture.com/admin/1.4/rest/?method=Report.GetElements', text=elements)
            m.post('https://api.omniture.com/admin/1.4/rest/?method=Segments.Get', text=segments)


            self.analytics = omniture.authenticate(creds['username'], creds['secret'])
            #force requests to happen in this method so they are cached
            self.analytics.suites[test_report_suite].metrics
            self.analytics.suites[test_report_suite].elements
            self.analytics.suites[test_report_suite].segments
Beispiel #2
0
def lambda_handler(event, context):

    #initialize dynamodb tables
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('reports')

    #log in and get report suite
    un = "APIteam:T-Mobile USA"
    sec = "936bf8cd2f1964e19e87ad81d7e04c32"
    analytics = omniture.authenticate(un, sec)
    tmobusprod = analytics.suites["tmobusprod"]

    #create reports and write to array
    for i in reports:
        try:
            report = tmobusprod.jsonReport(i[1]). async ()
            while (report.check() == False):
                report.check()
            else:
                table.put_item(
                    Item={
                        'title': i[0],
                        'report_id': getattr(report, "id"),
                        'datetime': str(now)
                    })
        except KeyError:
            continue
def Omnituredata():
    analytics = omniture.authenticate('', '')
    suite = analytics.suites['']
    query = suite.report \
        .element('listvar1',disable_validation=True) \
        .metric('instances',disable_validation=True) \
        .range(start = '2018-05-03', stop = "2018-05-06") \
        .run()
    return query
Beispiel #4
0
    def test_os_environ(self):
        test = omniture.authenticate({'OMNITURE_USERNAME':creds['username'],
                                           'OMNITURE_SECRET':creds['secret']})
        self.assertEqual(test.username,creds['username'],
                         "The username isn't getting set right: {}"
                         .format(test.username))

        self.assertEqual(test.secret,creds['secret'],
                         "The secret isn't getting set right: {}"
                         .format(test.secret))
    def test_os_environ(self):
        test = omniture.authenticate({'OMNITURE_USERNAME':creds['username'],
                                           'OMNITURE_SECRET':creds['secret']})
        self.assertEqual(test.username,creds['username'],
                         "The username isn't getting set right: {}"
                         .format(test.username))

        self.assertEqual(test.secret,creds['secret'],
                         "The secret isn't getting set right: {}"
                         .format(test.secret))
Beispiel #6
0
 def setUp(self):
     self.analytics = omniture.authenticate(creds['username'],
                                            creds['secret'])
 def setUp(self):
     self.analytics = omniture.authenticate(creds['username'], creds['secret'])
#!/usr/bin/python
# Example using a character LCD plate.

# import Adafruit_CharLCD
import omniture
import os
import time

script_dir = os.path.dirname(__file__)
abs_file_path = os.path.join(script_dir, "auth/key.txt")

with open (abs_file_path, "r") as myfile:
    myKey = myfile.read().split('\n')


analytics = omniture.authenticate(myKey[0], myKey[1])

def realtimeOrders():
    params = {
        "reportDescription": {
            "source": "realtime",
            "reportSuiteID": "avgcorporatepublicww",
            "metrics": [
                { "id": "orders" }
            ]
        }
    }
    response = analytics.request('Report', 'Run', params)
    period = response['report']['period']
    total = response['report']['totals'][0]
    print period + ': ' + total
Beispiel #9
0
        dict_data['data'].append({'{#SKU}': sku})
        for sku in get_skus(skus).keys()
    ]
    print(dict_data)


if __name__ == '__main__':

    try:
        bandeira = sys.argv[1]
        funcao = sys.argv[2]
    except:
        bandeira = 'np-extra'
        funcao = 'discovery'

    analytics = omniture.authenticate(username, secret)
    suite = analytics.suites[bandeira]

    dt_to = datetime.now()
    dt_from = date(dt_to.year, dt_to.month, 1)

    report = suite.report.range(dt_from.strftime('%Y/%m/%d'),
                                dt_to.strftime('%Y/%m/%d')).ranked(
                                    metrics=['orders'],
                                    elements=['product'],
                                    top=200).sync()

    if funcao == 'discovery':
        discovery(report.data['orders'])
    elif funcao == 'metricas':
        get_precos(report.data['orders'])
Beispiel #10
0
creds = {}
creds['username'] = os.environ['OMNITURE_USERNAME']
creds['secret'] = os.environ['OMNITURE_SECRET']
test_report_suite = "royalcaribbeanprod"

data = {
    "accessLevel": "shared",
    "fields": ["definition"],
    "filters": {
        "name": "Test AeM: Weekly EM Report Launch Date Filter"
    }
}

test = omniture.authenticate({
    'OMNITURE_USERNAME': creds['username'],
    'OMNITURE_SECRET': creds['secret']
})
suite = test.suites[test_report_suite]
segments = suite.retrieve_segments(data)
#print(len(segments))
#print(json.dumps(segments, indent=4))

for segment in segments:
    print(segment['id'], segment["name"])
    rules = segment["definition"]['container']['rules']
    for rule in rules:
        d = datetime.strptime(rule['value'], '%m/%d/%Y') + timedelta(days=7)
        rule['value'] = d.strftime("%m/%d/%Y")
    segment["reportSuiteID"] = test_report_suite
    #response =  suite.save_segment(segment)
    #print(response)
Beispiel #11
0
 def setUp(self):
     self.analytics = omniture.authenticate(creds['username'], creds['secret'])
     reportdef = self.analytics.suites[test_suite].report
     queue = []
     queue.append(reportdef)
     self.report = omniture.sync(queue)