def test_load_activities(self):
     loaders.load_activity(self.activities_data[0])
     activity = Activity.objects.all()[0]
     self.assertEqual(activity.cc_id, 'a07e5ke3u5dgy7a11on')
     self.assertEqual(activity.errors, 0)
     self.assertEqual(activity.insert_time, datetime.datetime(2012, 2, 3, 13,55, 33))
     self.assertEqual(activity.run_start_time, datetime.datetime(2012, 2, 3, 13, 56, 12))
     self.assertEqual(activity.run_finish_time, datetime.datetime(2012, 2, 3, 13, 57, 52))
     self.assertEqual(activity.status, 'COMPLETE')
     self.assertEqual(activity.transaction_count, 15578)
     self.assertEqual(activity.activity_type, 'EXPORT_CONTACTS')
     self.assertEqual(activity.updated, datetime.datetime(2012, 2, 3, 13, 57, 52))
     self.assertEqual(activity.synced, False)
 def test_load_activities(self):
     loaders.load_activity(self.activities_data[0])
     activity = Activity.objects.all()[0]
     self.assertEqual(activity.cc_id, 'a07e5ke3u5dgy7a11on')
     self.assertEqual(activity.errors, 0)
     self.assertEqual(activity.insert_time,
                      datetime.datetime(2012, 2, 3, 13, 55, 33))
     self.assertEqual(activity.run_start_time,
                      datetime.datetime(2012, 2, 3, 13, 56, 12))
     self.assertEqual(activity.run_finish_time,
                      datetime.datetime(2012, 2, 3, 13, 57, 52))
     self.assertEqual(activity.status, 'COMPLETE')
     self.assertEqual(activity.transaction_count, 15578)
     self.assertEqual(activity.activity_type, 'EXPORT_CONTACTS')
     self.assertEqual(activity.updated,
                      datetime.datetime(2012, 2, 3, 13, 57, 52))
     self.assertEqual(activity.synced, False)
Beispiel #3
0
    def handle(self, *args, **options):

        ##### GENERATE A BULK EXPORT #####
        # Set up CC connection
        cnx = CTCTConnection(API_KEY, USER, PASSWORD)

        # GENERATE EXPORT ACTIVITY FOR ACTIVE CONTACTS
        active_list_uri = 'http://api.constantcontact.com/ws/%s/lists/active' % USER

        # Create an export activity as a csv file
        activity_uri = cnx.create_activity(type='EXPORT_CONTACTS',
                                           lists=[active_list_uri],
                                           data={'fileType': 'TXT'})

        activity_id = activity_uri.rpartition('/')[-1]

        # Check the activity status
        activity = cnx.get_activity(activity_id)

        # Load Bulk Export Activity
        load_activity(activity)

        #### TRY IMPORTING BULK EXPORT ####
        # retry download up to 5 times over 10 minuteS
        retries = 5
        outcome = 'failed'
        while retries > 0 and outcome == 'failed':
            activity = cnx.get_activity(activity_id)
            activity_status = activity['status']
            if activity_status == 'COMPLETE':
                #TODO:emails = fetch_bulk_contacts_export(activity_id)
                #TODO: sync_bulk_contacts(emails)
                outcome = 'succeeded'
            else:
                retries -= 1
                time.sleep(120)

        #TODO: Log this
        print 'Data load %s for activity_id: %s' % (outcome, activity_id)
    def handle(self, *args, **options):

        ##### GENERATE A BULK EXPORT #####
        # Set up CC connection
        cnx = CTCTConnection(API_KEY, USER, PASSWORD)

        # GENERATE EXPORT ACTIVITY FOR ACTIVE CONTACTS
        active_list_uri = "http://api.constantcontact.com/ws/%s/lists/active" % USER

        # Create an export activity as a csv file
        activity_uri = cnx.create_activity(type="EXPORT_CONTACTS", lists=[active_list_uri], data={"fileType": "TXT"})

        activity_id = activity_uri.rpartition("/")[-1]

        # Check the activity status
        activity = cnx.get_activity(activity_id)

        # Load Bulk Export Activity
        load_activity(activity)

        #### TRY IMPORTING BULK EXPORT ####
        # retry download up to 5 times over 10 minuteS
        retries = 5
        outcome = "failed"
        while retries > 0 and outcome == "failed":
            activity = cnx.get_activity(activity_id)
            activity_status = activity["status"]
            if activity_status == "COMPLETE":
                # TODO:emails = fetch_bulk_contacts_export(activity_id)
                # TODO: sync_bulk_contacts(emails)
                outcome = "succeeded"
            else:
                retries -= 1
                time.sleep(120)

        # TODO: Log this
        print "Data load %s for activity_id: %s" % (outcome, activity_id)