def QueryMySql(query): # Create object for internal database methods (mySQL) mysqlDb = MySqlTask(config.mysql_username, config.mysql_password, config.mysql_host, config.mysql_database) mysqlDb.connect() results = mysqlDb.select_query(query) mysqlDb.close() return results
# Pull from SFDC query = "Select Id, DataSift_UserID__c, Name FROM Account WHERE Account_Status__c = 'Customer' and DataSift_UserID__c != '' and LastModifiedDate > {0}".format(startTime) results = sfdc.sfdc_query(query) if results['count'] > 0: for account in results['results']: if account['Id'] not in sfdc_update: sfdc_update[account['Id']] = [] ids = re.findall(r'[0-9]+', account['DataSift_UserID__c']) if len(ids): for i in ids: # Query Users table mquery = "SELECT user_id, email, username FROM users WHERE user_id = '{0}'".format(i) mysqlDb.connect() r = mysqlDb.select_query(mquery) if len(r): data = { 'user_id' : r[0][0], 'email' : r[0][1], 'username' : r[0][2], 'name' : account['Name'].decode('utf-8'), 'accountid' : account['Id'] } print data insert = """ INSERT into account_link (datasift_user_id, datasift_username, datasift_email_address, accountid, accountname) VALUES ('%(user_id)s', '%(username)s', '%(email)s', '%(accountid)s', '%(name)s') ON DUPLICATE KEY UPDATE datasift_username = '******', datasift_email_address = '%(email)s', accountid = '%(accountid)s', accountname = '%(name)s'