def main(account_id, passcode, region, path_json, path_csv, type_of_download): clevertap = CleverTap(account_id, passcode, region=region) result = [] if type_of_download not in ["event", "profile"]: raise Exception("unknown record type %s" % type) return start_time = datetime.datetime.now() print("Downloading...") try: with open(path_json) as data_file: data = json.load(data_file) if type_of_download == "profile": result = clevertap.profiles(data, MAX_BATCH_SIZE) elif type_of_download == "event": result = clevertap.events(data, MAX_BATCH_SIZE) _convert_to_csv(result, path_csv) except Exception as e: print(e) finally: end_time = datetime.datetime.now() processing_time = end_time - start_time print(("Processing Time: %s" % processing_time))
def main(account_id, passcode, path, type, dryrun): clevertap = CleverTap(account_id, passcode) data = [] if type not in ["event", "profile"]: raise Exception("unknown record type %s" % type) return if type == "event": raise NotImplementedError("Event handling not yet implemented") return f = open(path, 'rt') try: reader = csv.DictReader(f) for row in reader: record = process_raw_record(row, type) if record is not None: if dryrun: print record data.append(record) else: print "unable to process row skipping: %s" % row count = len(data) if count <= 0: print "no records to process" f.close() return if not dryrun: print "starting upload for %s records" % count processed = 0 while processed < count: remaining = count - processed batch_size = MAX_BATCH_SIZE if remaining > MAX_BATCH_SIZE else remaining batch = data[processed:processed + batch_size] if not dryrun: res = clevertap.upload(batch) print res processed += batch_size print "processed %s records" % processed except Exception, e: print e
def main(account_id, passcode, region, path, mapping_path, type, dryrun): clevertap = CleverTap(account_id, passcode, region=region) data = [] if type not in ["event", "profile"]: raise Exception("unknown record type %s" % type) return mapping = None if mapping_path is not None: try: with open(mapping_path) as mapping_file: mapping = json.load(mapping_file) except Exception, e: print e pass
import random import logging logger = logging.getLogger() logger.setLevel(logging.INFO) TABLE_NAME = "quotes" INDEX_NAME = "PersonalityTypeIndex" CT_ACCOUNT_ID = "6Z8-64Z-644Z" CT_ACCOUNT_PASSCODE = "WVE-SAD-OAAL" QUOTE_BYTE_LENGTH = 40 try: clevertap = CleverTap(CT_ACCOUNT_ID, CT_ACCOUNT_PASSCODE) except Exception, e: logger.error(e) clevertap = None try: dynamo = boto3.resource('dynamodb').Table(TABLE_NAME) except Exception, e: logger.error(e) dynamo = None LENGTH_BY_PREFIX = [ (0xC0, 2), # first byte mask, total codepoint length (0xE0, 3), (0xF0, 4),
def setUp(self): self.clevertap = CleverTap(CT_ACCOUNT_ID, CT_ACCOUNT_PASSCODE)
class CleverTapTests(unittest.TestCase): def setUp(self): self.clevertap = CleverTap(CT_ACCOUNT_ID, CT_ACCOUNT_PASSCODE) def test_upload(self): data = [ {"type":"event", "identity":"6264372124", "evtName":"choseNewFavoriteFood", "evtData":{ "value":random.choice(foods), }, }, {"type":"profile", "identity":"6264372124", "ts":int(time.time()), "profileData":{ "favoriteColor":random.choice(colors), "Age":30, "Phone":"+14155551234", "Email":"*****@*****.**", }, }, {"type":"event", "FBID":"34322423", "evtName":"Product viewed", "evtData":{ "Product name":"Casio Chronograph Watch", "Category":"Mens Watch", "Price":59.99, "Currency":"USD" }, }, {'type': 'profile', 'objectId': "-2ce3cca260664f70b82b1c6bb505f462", 'profileData': {'favoriteFood': 'hot dogs'} }, {'type': 'event', 'objectId': "-2ce3cca260664f70b82b1c6bb505f462", 'evtName': 'choseNewFavoriteFood', 'evtData': {} }, {"type":"event", "identity":"*****@*****.**", "ts":"%s"%int(time.time()), "evtName":"Charged", "evtData":{ "Amount":300, "Currency":"USD", "Payment mode":"Credit Card", "Items":[ { "Category":"books", "Book name":"The millionaire next door", "Quantity":1 }, { "Category":"books", "Book name":"Achieving inner zen", "Quantity":4 } ] }, }, ] res = self.clevertap.upload(data) or {} unprocessed = res.get("unprocessed", []) self.assertEqual(len(unprocessed), 0, "%s records failed"%(len(unprocessed))) def test_download_events(self): query = {"event_name": "choseNewFavoriteFood", "props": [{"name":"value","operator":"contains", "value":"piz"}], "from": 20160810, "to": 20170208 } res = self.clevertap.events(query) if len(res) > 0: print res[0] self.assertTrue( len(res) > 0 ) def test_download_profiles(self): query = {"event_name": "choseNewFavoriteFood", "props": [{"name":"value","operator":"contains", "value":"piz"}], "from": 20160810, "to": 20170208 } res = self.clevertap.profiles(query) if len(res) > 0: print res[0] self.assertTrue( len(res) > 0 ) def test_profile_by_id(self): res = self.clevertap.profile(identity="6264372124") or {} print res self.assertTrue( res.get("status", None) == "success" )
class CleverTapTargetTests(unittest.TestCase): def setUp(self): self.clevertap = CleverTap(CT_ACCOUNT_ID, CT_ACCOUNT_PASSCODE) def test_create(self): payload = { "name": "test2", "when": "now", "where": { "event_name": "App Launched", "from": 20160101, "to": 20160313, "common_profile_prop": { "profile_fields": [ { "name": "channels", "value": ["bhome", "bhometest530a70c93b83286003f6bb5a"] } ] } }, "content":{ "title":"Hello!", "body":"Strictly Green Lantern fans only!", "platform_specific": { "ios": { "deep_link": "judepereira.com", "sound_file": "judepereira.wav", "category": "reactive", "badge_count": 1, "foo": "bar_ios" }, "android": { "background_image": "http://judepereira.com/a.jpg", "default_sound": True, "deep_link": "judepereira.com", "foo": "bar_android" } } }, "devices": [ "android", "ios" ], } res = self.clevertap.targets(self.clevertap.TargetActions.CREATE, payload) or {} print res status = res.get("status", None) self.assertEqual(status, "success", "create status is %s"%status) def test_estimate(self): payload = { "name": "green freedom", "when": "now", "where": { "event_name": "App Launched", "from": 20160101, "to": 20160313, }, "content":{ "title":"Hello!", "body":"Strictly Green Lantern fans only!", "platform_specific": { "ios": { "deep_link": "judepereira.com", "sound_file": "judepereira.wav", "category": "reactive", "badge_count": 1, "foo": "bar_ios" }, "android": { "background_image": "http://judepereira.com/a.jpg", "default_sound": True, "deep_link": "judepereira.com", "foo": "bar_android" } } }, "devices": [ "android", "ios" ], } res = self.clevertap.targets(self.clevertap.TargetActions.ESTIMATE, payload) or {} print res status = res.get("status", None) self.assertEqual(status, "success", "estimate status is %s"%status) def test_list(self): payload = {"from": 20160101, "to": 20160312} res = self.clevertap.targets(self.clevertap.TargetActions.LIST, payload) or {} print res status = res.get("status", None) self.assertEqual(status, "success", "list status is %s"%status) def test_stop(self): payload = {"id": 1457737861} res = self.clevertap.targets(self.clevertap.TargetActions.STOP, payload) or {} print res status = res.get("status", None) self.assertEqual(status, "success", "stop status is %s"%status) def test_result(self): payload = {"id": 1457744284} res = self.clevertap.targets(self.clevertap.TargetActions.RESULT, payload) or {} print res status = res.get("status", None) self.assertEqual(status, "success", "result status is %s"%status)
import random import logging logger = logging.getLogger() logger.setLevel(logging.INFO) TABLE_NAME = "quotes" INDEX_NAME = "PersonalityTypeIndex" CT_ACCOUNT_ID = "6Z8-64Z-644Z" CT_ACCOUNT_PASSCODE = "WVE-SAD-OAAL" QUOTE_BYTE_LENGTH = 40 try: clevertap = CleverTap(CT_ACCOUNT_ID, CT_ACCOUNT_PASSCODE) except Exception, e: logger.error(e) clevertap = None try: dynamo = boto3.resource('dynamodb').Table(TABLE_NAME) except Exception, e: logger.error(e) dynamo = None LENGTH_BY_PREFIX = [ (0xC0, 2), # first byte mask, total codepoint length (0xE0, 3), (0xF0, 4), (0xF8, 5),
class CleverTapTests(unittest.TestCase): def setUp(self): self.clevertap = CleverTap(CT_ACCOUNT_ID, CT_ACCOUNT_PASSCODE) def test_upload(self): data = [ {"type":"event", "Identity":"6264372124", "ts":int(time.time()), "evtName":"choseNewFavoriteFood", "evtData":{ "value":random.choice(foods) }, }, {"type":"profile", "Identity":"6264372124", "ts":int(time.time()), "profileData":{ "favoriteColor":random.choice(colors), "Age":30, "Phone":"+14155551234", "Email":"*****@*****.**", }, }, {"type":"event", "FBID":"34322423", "ts":int(time.time()), "evtName":"Product viewed", "evtData":{ "Product name":"Casio Chronograph Watch", "Category":"Mens Watch", "Price":59.99, "Currency":"USD" }, }, {'type': 'profile', 'WZRK_G': "-2ce3cca260664f70b82b1c6bb505f462", 'ts': int(time.time()), 'profileData': {'favoriteFood': 'pizza'} }, {'type': 'event', 'WZRK_G': "-2ce3cca260664f70b82b1c6bb505f462", 'ts': int(time.time()), 'evtName': 'choseNewFavoriteFood', 'evtData': {} }, {"type":"event", "Identity":"*****@*****.**", "ts":int(time.time()), "evtName":"Charged", "evtData":{ "Amount":300, "Currency":"USD", "Payment mode":"Credit Card", "Items":[ { "Category":"books", "Book name":"The millionaire next door", "Quantity":1 }, { "Category":"books", "Book name":"Achieving inner zen", "Quantity":4 } ] }, }, ] res = self.clevertap.up(data) or {} print res unprocessedRecords = res.get("unprocessedRecords:", []) self.assertEqual(len(unprocessedRecords), 0, "%s records failed"%(len(unprocessedRecords))) def test_download_events(self): query = {"event_name": "choseNewFavoriteFood", "from": 20150810, "to": 20151025 } res = self.clevertap.events(query) self.assertTrue( len(res) > 0 ) def test_download_profiles(self): query = {"event_name": "choseNewFavoriteFood", "from": 20150810, "to": 20151025 } res = self.clevertap.profiles(query) self.assertTrue( len(res) > 0 )