当前位置: 首页>>代码示例>>Python>>正文


Python Salesforce.apexecute方法代码示例

本文整理汇总了Python中simple_salesforce.Salesforce.apexecute方法的典型用法代码示例。如果您正苦于以下问题:Python Salesforce.apexecute方法的具体用法?Python Salesforce.apexecute怎么用?Python Salesforce.apexecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simple_salesforce.Salesforce的用法示例。


在下文中一共展示了Salesforce.apexecute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_signup_info

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]
def send_signup_info( name, email, address=''):
    try:
        res = None
        payload = {'donorName': name, 'email': email, 'donorAddress': address}
        sf = Salesforce(username=SFDC_ACCOUNT, password=SFDC_PASSWORD, security_token=SFDC_TOKEN)
        logger.info('send sign-up to SFDC with data: %s', payload)
        res = sf.apexecute(SFDC_REVOLV_SIGNUP, method='POST', data=payload)
        if res.lower() != 'success':
            raise SFDCException(res)
        logger.info('SFDC sign-up: sucess.')
    except Exception as e:
        logger.error('SFDC sign-up: ERROR for name: %s and data: %s, res: %s', name, payload, res, exc_info=True)
        send_signup_info.retry(args=[name, email, address], countdown=INTERVAL, exc=e, max_retries=MAX_RETRIES)
开发者ID:deedee,项目名称:revolv,代码行数:15,代码来源:sfdc.py

示例2: send_donation_info

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]
def send_donation_info(name, amount, project, address=''):
    if not settings.SFDC_ACCOUNT:
        return
    try:
        res = None
        payload = {'donorName': name, 'projectName': project, 'donationAmount': amount, 'donorAddress': address}
        sf = Salesforce(username=SFDC_ACCOUNT, password=SFDC_PASSWORD, security_token=SFDC_TOKEN)
        logger.info('send donation to SFDC with data: %s', payload)
        res = sf.apexecute(SFDC_REVOLV_DONATION, method='POST', data=payload)
        if res.lower() != 'success':
            raise SFDCException(res)
        logger.info('SFDC donation: success.')
    except Exception as e:
        logger.error('SFDC donation: ERROR for name: %s and data: %s, res: %s', name, payload, res, exc_info=True)
        send_donation_info.retry(args=[name, amount, project, address], countdown=INTERVAL, exc=e,
                                 max_retries=MAX_RETRIES)
开发者ID:Kamikace,项目名称:revolv,代码行数:18,代码来源:sfdc.py

示例3: send_signup_info

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]
def send_signup_info(name, email, address=''):
    if not settings.SFDC_ACCOUNT:
        return
    try:
        res = None
        payload = {'donorName': name, 'email': email, 'donorAddress': ''}
        sf = Salesforce(
            username=settings.SFDC_ACCOUNT,
            security_token=settings.SFDC_TOKEN,
            password=settings.SFDC_PASSWORD
        )
        logger.info('send sign-up to SFDC with data: %s', payload)
        res = sf.apexecute(settings.SFDC_REVOLV_SIGNUP, method='POST', data=payload)
        if res.lower() != 'success':
            raise SFDCException(res)
        logger.info('SFDC sign-up: sucess.')
    except Exception as e:
        logger.error('SFDC sign-up: ERROR for name: %s and data: %s, res: %s', name, payload, res, exc_info=True)
开发者ID:RE-volv,项目名称:revolv,代码行数:20,代码来源:sfdc.py

示例4: Salesforce

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]
__author__ = 'Brad'
from simple_salesforce import Salesforce
import json
sf = Salesforce( username='[email protected]', password='fmr0cks!', security_token='vnWYJMNtLbDPL9NY97JP9tJ5', sandbox=True)
print sf

metricData ={
    "patientId": "DCE-2762",
    "timestamp": "6/11/2015 12:00 AM",

    "roomPercentages": [
        {
            "room": "Bathroom",
            "percentage": 100
        },
        {
            "room": "Livingroom",
            "percentage": 100
        },
        {
            "room": "Kitchen",
            "percentage": 100
        }
    ]
}
print metricData
result = sf.apexecute('FMMetrics/insertMetrics', method='POST', data=metricData)
print result
开发者ID:PhoenixYanrongLi,项目名称:CareEcoSystem_ServerCodeNew,代码行数:30,代码来源:salesforceTest.py

示例5: __init__

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]
class EventProcessing:

    def __init__(self, database, database_name, username='[email protected]', password='moxie100', security_token='rUrhVtWfeJAcZ6Wf1S7XZml4', sandbox=True):

        self.dataB = MySQLdb.connect(host=database[0], user=database[1], passwd=database[2])
        self.cur = self.dataB.cursor()
        self.databaseName = database_name
        self.patient_id = self.databaseName[1:]
        self.length = 30*86400
        self.data = []
        self.sf = Salesforce(username=username, password=password, security_token=security_token, sandbox=sandbox)


    def set_event_length(self, length):
        """

        @param length: double(days)
        @return:true
        """
        self.length = length*86400
        return True

    def get_event_data(self, data_type, table_name):
        """
        @param data_type: str of the column selected, pass * for all data in table
        @param table_name: str of the name of the table
        @return: Double tuple of steps
        """
        current_date = self.get_current_date()
        date_from_length = current_date-self.length
        sql = 'SELECT '+data_type+' FROM '+self.databaseName+'.'+table_name+' WHERE datetime >= '+str(date_from_length)
        self.cur.execute(sql)
        event_data = self.cur.fetchall()
        if len(event_data) == 0:
            return []
        else:
            return list(zip(*event_data)[0])

    @staticmethod
    def get_current_date(self):
        """

        @return:returns the current date in seconds from the epoch
        """
        epoch = datetime.datetime.utcfromtimestamp(0)
        current_date = datetime.datetime.now()
        current_date = current_date-epoch
        current_date = current_date.total_seconds()
        return current_date

    def upload_to_sales_force(self, apex_list):

        event_dict = {
            "metric": apex_list[0],
            "severity": apex_list[1],
            "metricValue": apex_list[2],
            "message": apex_list[3]
        }

        json_dict = {
            "patientId": self.patient_id,
            "event": event_dict
        }

        result = self.sf.apexecute('FMEvent/insertEvents', method='POST', data=json_dict)

        return result

    def upload_to_database(self, event_data):
        """

        @param event_data: List of event data referenced to objnamelist
        @return:True on success
        """

        # Create event table in database if it does not yet exist
        try:
            table_string = ''
            for i in self.objnamelist:
                # Splice out __c in object names
                table_string += i[0:-3] + ' VARCHAR(255),'

            sql = "CREATE TABLE " + self.databaseName + "." + "Events (datetime DOUBLE NOT NULL,"+table_string+" PRIMARY KEY(datetime))"
            self.cur.execute(sql)

        except MySQLdb.Error:
            print "Event Table found in database: "+self.databaseName

            try:
                # Try to see if we can resize the event table

                #Get number of columns
                sql = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = '"+self.databaseName+"' AND table_name = 'Events' "
                self.cur.execute(sql)
                columns = int(list(self.cur.fetchall())[0][0])

                #Build list of new columns to add
                tables = ""
                if columns < len(self.objnamelist)+1:
                    for i in range(0, len(self.objnamelist)-(columns-1)):
#.........这里部分代码省略.........
开发者ID:PhoenixYanrongLi,项目名称:CareEcoSystem_ServerCode,代码行数:103,代码来源:eventProcessingClass.py

示例6: MetricsClass

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]

#.........这里部分代码省略.........
            return []
        else:
            latest_data = self.fetchall()

        if len(latest_data) == 0:
            return []
        else:
            return zip(*list(zip(*latest_data)))[0][0]

    def read_timestamp(self):
        """
        Reads in the timestamp of the last processed data
        :return: Timestamp if exists, otherwise NULL
        """
        if not self.fetch_from_database(database_name = self.database_name,
                                        table_name    = 'metricsprofile',
                                        to_fetch      = 'timestamp',
                                        where         = [['table_name', self.table_name], ['type_name', self.typename]]):
            # If no analysisprofile database exists then return the start timestamp
            return self.read_start_stamp()

        else:
            # If timestamp column does exist in analysis profile, return it if it has length,
            # otherwise return the start_stamp
            timestamp = self.fetchall()

            if len(timestamp) == 0:
                # If no timestamp in timestamp column, return start_stamp
                return self.read_start_stamp()

            else:
                # If timestamp exists in timestamp column, return that
                timestamp = list(zip(*timestamp))[0][0]
                return timestamp

    def write_timestamp(self, timestamp):
        """
        Write the latest timestamp, in this case it means the end of a window
        :param timestamp:
        :return:
        """
        return self.insert_into_database(database_name       = self.database_name,
                                         table_name          = 'metricsprofile',
                                         column_names        = ['table_name', 'type_name', 'timestamp'],
                                         values              = [self.table_name, self.typename, timestamp],
                                         on_duplicate_update = [ 2 ])

    def upload_to_database(self, start_window, end_window, metric):
        """
        Uploads the metric to the database ['VARCHAR(100) NOT NULL PRIMARY KEY', 'FLOAT']
        :return:
        """
        self.create_table(database_name= self.database_name,
                          table_name   = self.metric_type,
                          column_names = ['start_window', 'end_window', 'metric'],
                          column_types = ['VARCHAR(100) NOT NULL PRIMARY KEY', 'VARCHAR(100) NOT NULL', 'FLOAT'])
        self.insert_into_database(database_name = self.database_name,
                                  table_name    = self.metric_type,
                                  column_names  = ['start_window', 'end_window', 'metric'],
                                  values        = [start_window, end_window, metric])
        return True

    def upload_to_salesforce(self, timestamp, metric):
        """
        Uploads the metric to salesforce
        :return:
        """
        metric_data = {
            "patientId": self.patient_id,
            "timestamp": self.utc_to_datetime(timestamp).strftime('%x'),
            "metricList":[
            {
                "metric": self.metric_type,
                "metricValue": metric
            }]
        }
        self.sf.apexecute('FMMetrics/insertMetrics', method='POST', data=metric_data)
        return True

    def run(self):
        """

        :return:
        """
        timestamp = self.read_timestamp
        # If no timestamp found, break the analysis code. Bad Profile!
        if timestamp is None: return False

        windows = self.get_stamp_windows()
        for i in windows:
            start_stamp = i[0]
            end_stamp = i[1]
            data = self.poll_data(start_stamp)
            if data != []:
                windowed_data  = self.split_to_windows(data)
                metric = self.process_data(windowed_data)
                self.upload_to_database(start_stamp, end_stamp, metric)
                self.upload_to_salesforce(start_stamp, metric)
                self.write_timestamp(start_stamp)
                return True
开发者ID:PhoenixYanrongLi,项目名称:CareEcoSystem_ServerCodeNew,代码行数:104,代码来源:MetricsClass.py

示例7: MetricsClass

# 需要导入模块: from simple_salesforce import Salesforce [as 别名]
# 或者: from simple_salesforce.Salesforce import apexecute [as 别名]
class MetricsClass(multiprocessing.Process, DatabaseWrapper):

    def __init__(self, database, patient_id, table_name, metric_type):
        logging.warning('Watch out!')
        multiprocessing.Process.__init__(self)
        DatabaseWrapper.__init__(self, database)
        self.database_name = '_' + patient_id
        self.table_name    = table_name
        self.metric_type   = metric_type
        self.sf = Salesforce(username='[email protected]',
                             password='_moxie100',
                             security_token='V6oPmGSaXW6Q5cv8MAEhLqCK',
                             sandbox=True)

    @staticmethod
    def get_day_window():
        """
        Returns the window between the current day and the last day
        :return:
        """
        current_date = datetime.datetime.now()
        start_window = datetime.datetime(current_date.year,
                                         current_date.month,
                                         current_date.day,
                                         current_date.hour) - datetime.timedelta(hours=12)
        start_window = start_window.strftime('%y-%m-%dT%H:%M:%S.%f')
        start_window = GenericFileUploader.timestamp_to_UTC(start_window)

        end_window   = datetime.datetime(current_date.year, current_date.month, current_date.day)
        end_window   = end_window.strftime('%y-%m-%dT%H:%M:%S.%f')
        end_window   = GenericFileUploader.timestamp_to_UTC(end_window)

        return start_window, end_window

    def poll_data(self, start_window, end_window):
        """
        Returns the data between the time frame specified
        :return:
        """

        if not self.fetch_from_database(database_name = self.database_name,
                                        table_name    = self.table_name,
                                        where         = [['timestamp', '<', start_window],
                                                         ['timestamp', '>=', end_window]],
                                        order_by      = ['timestamp', 'ASC']):
            return []
        else:
            metric_data = self.fetchall()

        if len(metric_data) == 0:
            return []
        else:
            return zip(*list(zip(*metric_data)))

    @abc.abstractmethod
    def process_data(self, data, start_window):
        """
        Returns the processed metric
        :param data:
        :return:
        """
        return

    def upload_to_database(self, metric, metric_names, metric_types):
        """
        Uploads the metric to the database ['VARCHAR(100) NOT NULL PRIMARY KEY', 'FLOAT']
        :return:
        """
        self.create_table(database_name= self.database_name,
                          table_name   = self.metric_type,
                          column_names = metric_names,
                          column_types = metric_types)
        self.insert_into_database(database_name = self.database_name,
                                  table_name    = self.metric_type,
                                  column_names  = ['timestamp', 'metric'],
                                  values        = metric)
        return True

    def upload_to_salesforce(self, metric):
        """
        Uploads the metric to salesforce
        :return:
        """
        metric_data = {
            "patientId": self.database_name[1:],
            "metricList": [{
                "metric": self.metric_type,
                "metricValue": metric[1]}
            ]
        }
        self.sf.apexecute('FMMetrics/insertMetrics', method='POST', data=metric_data)
        return True

    def run(self):
        """

        :return:
        """
        start_window, end_window = MetricsClass.get_day_window()
        data = self.poll_data(start_window, end_window)
#.........这里部分代码省略.........
开发者ID:PhoenixYanrongLi,项目名称:CareEcoSystem_ServerCode,代码行数:103,代码来源:MetricsClass.py


注:本文中的simple_salesforce.Salesforce.apexecute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。