Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import salesforce_bulk as sf
- from time import sleep
- ## PRODUCTION ENV
- addresses = ['']
- username = ''
- password = ''
- security_token = ''
- client = ''
- secret = ''
- ###############################################################################
- ###############################################################################
- def SF_Dataframe(query_list, object_list):
- print('Establishing Connection to Salesforce')
- bulk = sf.SalesforceBulk(username = username,
- password = password, security_token = security_token,
- sandbox = False)
- print('Connection Established')
- def Run_SF_Query(query, object_name):
- job_id = bulk.create_query_job(object_name = object_name)
- batch_id = bulk.query(job_id = job_id, soql = query)
- bulk.close_job(job_id)
- while not bulk.is_batch_done(batch_id):
- sleep(1)
- results = bulk.get_all_results_for_query_batch(batch_id)
- for result in results:
- df = pd.read_csv(result)
- break
- return df
- dfs = []
- for query, obj in zip(query_list, object_list):
- df = Run_SF_Query(query, obj)
- print('-------------------------------------------')
- print('%s object has been queried.' % obj)
- print('-------------------------------------------')
- print()
- df.drop_duplicates(inplace = True)
- dfs.append(df)
- return dfs
- #Below are the SOQL queries to send to Salesforce
- queries = ["""
- """]
- #These are the objects being queried
- objects = ['']
- #Returns a list (dfs) that has a dataframe for each query you ran
- dfs = SF_Dataframe(queries, objects)
Add Comment
Please, Sign In to add comment