[英]How to extract raw data from Salesforce using Beatbox python API
I am using the following code to extract data from Salesforce using beatbox python API. 我使用以下代码使用beatbox python API从Salesforce中提取数据。
import beatbox
sf_username = "xyz@salesforce.com"
sf_password = "123"
sf_api_token = "ABC"
def extract():
sf_client = beatbox.PythonClient()
password = str("%s%s" % (sf_password, sf_api_token))
sf_client.login(sf_username, password)
lead_qry = "SELECT CountryIsoCode__c,LastModifiedDate FROM Country limit 10"
records = sf_client.query(lead_qry)
output = open('output','w')
for record in records:
output.write('\t'.join(record.values())
output.close()
if _name_ == '__main__':
extract()
But this is what I get in the output. 但这是我在输出中得到的。 How to get the raw data, just the values I see in the workbench.
如何获取原始数据,只是我在工作台中看到的值。 I don't want to parse each datatype and get the raw value.
我不想解析每个数据类型并获取原始值。
Actual Output: 实际产量:
[{'LastModifiedDate': datetime.datetime(2012, 11, 2, 9, 32, 4), 'CountryIsoCode_ c': 'AU', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 8, 18, 14, 0, 21), 'CountryIsoCode_ c': 'LX', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 12, 15, 20, 11), 'CountryIsoCode_ c': 'AE', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 12, 15, 20, 29), 'CountryIsoCode_ c': 'AR', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 2, 9, 32, 4), 'CountryIsoCode_ c': 'AT', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 2, 9, 32, 4), 'CountryIsoCode_ c': 'BE', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 12, 15, 21, 28), 'CountryIsoCode_ c': 'BR', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 12, 15, 21, 42), 'CountryIsoCode_ c': 'CA', 'type': 'Country _c', 'Id': ''}, {'
[{'LastModifiedDate':datetime.datetime(2012,11,2,9,32,4),'CountryIsoCode_ c':'AU','type':'Country _c','Id':''},{ 'LastModifiedDate':datetime.datetime(2012,8,18,14,0,21),'CountryIsoCode_ c':'LX','type':'Country _c','Id':''},{'LastModifiedDate ':datetime.datetime(2012,11,12,15,20,11),'CountryIsoCode_ c':'AE','type':'Country _c','Id':''},{'LastModifiedDate': datetime.datetime(2012,11,12,15,20,29),'CountryIsoCode_ c':'AR','type':'Country _c','Id':''},{'LastModifiedDate':datetime。 datetime(2012,11,2,9,32,4),'CountryIsoCode_ c':'AT','type':'Country _c','Id':''},{'LastModifiedDate':datetime.datetime( 2012,11,2,9,32,4),'CountryIsoCode_ c':'BE','type':'Country _c','Id':''},{'LastModifiedDate':datetime.datetime(2012, 11,12,15,21,28),'CountryIsoCode_c ':'BR','type':'Country _c','Id':''},{'LastModifiedDate':datetime.datetime(2012,11, 12,15,21,42),'CountryIsoCode_c ':'CA','type':'Country _c','Id':''},{' LastModifiedDate': datetime.datetime(2012, 11, 12, 15, 36, 18), 'CountryIsoCode_ c': 'CH', 'type': 'Country _c', 'Id': ''}, {'LastModifiedDate': datetime.datetime(2012, 11, 12, 15, 35, 8), 'CountryIsoCode_ c': 'CL', 'type': 'Country _c', 'Id': ''}]
LastModifiedDate':datetime.datetime(2012,11,12,15,36,18),'CountryIsoCode_ c':'CH','type':'Country _c','Id':''},{'LastModifiedDate' :datetime.datetime(2012,11,12,15,35,8),'CountryIsoCode_ c':'CL','type':'Country _c','Id':''}]
Expected Output: 预期产出:
AU 2012-11-02T09:32:04Z
LX 2012-08-18T14:00:21Z
If you work with table data you should use Pandas library 如果使用表数据,则应使用Pandas库
Here is an example: 这是一个例子:
import pandas as pd
from datetime import datetime
import beatbox
service = beatbox.PythonClient()
service.login('login_here', 'creds_here')
query_result = service.query("SELECT Name, Country, CreatedDate FROM Lead limit 5") # CreatedDate is a datetime object
records = query_result['records'] # records is a list of dictionaries
records is a list of dictionaries as you mentioned before 记录是您之前提到的字典列表
df = pd.DataFrame(records)
print (df)
Country CreatedDate Id Name type
0 United States 2011-05-26 23:39:58 qwe qwe Lead
1 France 2011-09-01 08:45:26 qwe qwe Lead
2 France 2011-09-01 08:37:36 qwe qwe Lead
3 France 2011-09-01 08:46:38 qwe qwe Lead
4 France 2011-09-01 08:46:57 qwe qwe Lead
Now you have table-style Dataframe object. 现在你有了表格式的Dataframe对象。 You can index multiple columns and rows:
您可以索引多个列和行:
df['CreatedDate']
0 2011-05-26 23:39:58
1 2011-09-01 08:45:26
2 2011-09-01 08:37:36
3 2011-09-01 08:46:38
4 2011-09-01 08:46:57
Here is more about pandas time functionality http://pandas.pydata.org/pandas-docs/stable/timeseries.html 这里有更多关于熊猫时间功能的信息http://pandas.pydata.org/pandas-docs/stable/timeseries.html
And here is about pandas http://pandas.pydata.org/pandas-docs/stable/install.html 这里是关于pandas http://pandas.pydata.org/pandas-docs/stable/install.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.