Пример #1
0
    def get(self, service=""):
        # test MailChimp API
        if service == "mailchimp":
            try:
                MAILCHIMP_API = os.environ.get('MAILCHIMP_API')
                headers = requests.utils.default_headers()
                client = MailChimp(mc_api=MAILCHIMP_API, timeout=60.0, request_headers=headers)
                client.lists.all(get_all=True, fields="lists.id")
                return {'status': 'OK'}, 200
            except Exception as e:
                log.error(str(e))

        # test GA API
        if service == "ga":
            try:
                # Define the auth scopes to request.
                scope = 'https://www.googleapis.com/auth/analytics.readonly'
                key_file_location = 'client_secrets.json'

                # Authenticate and construct service.
                service = get_service(api_name='analytics',
                                      api_version='v3',
                                      scopes=[scope],
                                      key_file_location=key_file_location)
                service.management().accounts().list().execute()
                return {'status': 'OK'}, 200

            except Exception as e:
                log.error(str(e))

        return {'status': 'ERROR'}, 500
Пример #2
0
    def get(self, count=10):
        try:
            rows = get_top_page_time(limit=count)
        except Exception as e:
            log.error(str(e))

            return {'status': 'ERROR'}, 500

        remote_address = request.environ.get('HTTP_X_REAL_IP',
                                             request.remote_addr)
        log.info("Request from {}".format(remote_address))
        output = ujson.loads(ujson.dumps(rows))

        return output, 200
Пример #3
0
    def get(self, title=""):
        if len(title) > 3:
            try:
                score = get_sharing_score(title)
                recommendations = build_recommended_words_text(title)

                return {
                    'score': score,
                    'recommendations': recommendations,
                    'status': 'OK'
                }, 200

            except Exception as e:
                log.error(str(e))

        return {'status': 'ERROR'}, 500
Пример #4
0
    def get(self, report):
        rows = dict()

        try:
            if report == "members_by_country":
                rows = get_members_by_country()

            if report == "open_rate_by_country":
                rows = get_open_rate_by_country()

        except Exception as e:
            log.error(str(e))

            return {'status': 'ERROR'}, 500

        remote_address = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
        log.info("Request from {}".format(remote_address))
        output = ujson.loads(ujson.dumps(rows))

        return output, 200
Пример #5
0
    def get(self, report, count=10):
        rows = dict()

        # TODO: do this with more style
        try:
            if report == "emailopens":
                rows = get_top_opens(limit=count)

            if report == "openrate":
                rows = get_top_open_rate(limit=count)
        except Exception as e:
            log.error(str(e))

            return {'status': 'ERROR'}, 500

        remote_address = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
        log.info("Request from {}".format(remote_address))
        output = ujson.loads(ujson.dumps(rows))

        return output, 200