Guest User

Untitled

a guest
Jul 17th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import pandas as pd
  2. import salesforce_bulk as sf
  3. from time import sleep
  4.  
  5. ## PRODUCTION ENV
  6. addresses = ['']
  7. username = ''
  8. password = ''
  9. security_token = ''
  10. client = ''
  11. secret = ''
  12.  
  13. ###############################################################################
  14. ###############################################################################
  15.  
  16. def SF_Dataframe(query_list, object_list):
  17. print('Establishing Connection to Salesforce')
  18. bulk = sf.SalesforceBulk(username = username,
  19. password = password, security_token = security_token,
  20. sandbox = False)
  21. print('Connection Established')
  22.  
  23. def Run_SF_Query(query, object_name):
  24. job_id = bulk.create_query_job(object_name = object_name)
  25.  
  26. batch_id = bulk.query(job_id = job_id, soql = query)
  27.  
  28. bulk.close_job(job_id)
  29.  
  30. while not bulk.is_batch_done(batch_id):
  31. sleep(1)
  32.  
  33. results = bulk.get_all_results_for_query_batch(batch_id)
  34.  
  35.  
  36. for result in results:
  37. df = pd.read_csv(result)
  38. break
  39.  
  40. return df
  41.  
  42. dfs = []
  43. for query, obj in zip(query_list, object_list):
  44. df = Run_SF_Query(query, obj)
  45. print('-------------------------------------------')
  46. print('%s object has been queried.' % obj)
  47. print('-------------------------------------------')
  48. print()
  49.  
  50. df.drop_duplicates(inplace = True)
  51. dfs.append(df)
  52.  
  53. return dfs
  54.  
  55. #Below are the SOQL queries to send to Salesforce
  56. queries = ["""
  57.  
  58. """]
  59.  
  60. #These are the objects being queried
  61. objects = ['']
  62.  
  63. #Returns a list (dfs) that has a dataframe for each query you ran
  64. dfs = SF_Dataframe(queries, objects)
Add Comment
Please, Sign In to add comment