我使用以下代码使用beatbox从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()但这就是我在输出中得到的。如何获取原始数据,仅仅是我在工作台中看到的值。我不想解析每个数据类型并获取原始值。
实际产出:
{'LastModifiedDate':datetime.datetime(2012年,11,2,9,32,4),‘农村等码_c’:'AU','type':'Country_c','Id':‘},{’},{'LastModifiedDate':datetime.datetime(2012年,8,18,14,0,21),‘农村等码_c’:'LX','type':'Country_c','Id':},{'LastModifiedDate':datetime.datetime(2012,11,12,15,20,11),‘农村代码_c’:'AE','type':'Country_c','Id':‘},{'LastModifiedDate':datetime.datetime(2012年,11,12,15,20,29),’农村代码_c‘:'AR','type':'Country_c','Id':’},{'LastModifiedDate':datetime.datetime(2012年,11,2,9,32,4),‘农村代码_c’:'AT','type':'Country_c','Id':‘},{'LastModifiedDate':datetime.datetime(2012年,11,2,9,32,4),’农村代码_c‘:'BE','type':'Country_c','Id':’},{'LastModifiedDate':datetime.datetime(2012年,11,12,15,21,28),‘农村代码_c’:'BR',“类型”:“Country_c”,“Id”:''},{'LastModifiedDate':datetime.datetime(2012年,11,12,15,21,42),‘农村等代码_c’:'CA','type':'Country_c','Id':‘},{'LastModifiedDate':datetime.datetime(2012年,11,12,15,36,18),“农村代码c”:'CH','type':'Country_c','Id':‘},{'LastModifiedDate':datetime.datetime(2012年,11,12,15,35,8),’农村等码_c‘:'CL','type':'Country_c','Id':’}
预期产出:
AU 2012-11-02T09:32:04Z
LX 2012-08-18T14:00:21Z发布于 2014-06-02 11:18:17
如果您使用表数据,则应该使用Pandas库。
下面是一个示例:
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“记录”是您前面提到的字典列表。
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现在您有了表样式的Dataframe对象。可以索引多个列和行:
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以下是有关熊猫时间功能http://pandas.pydata.org/pandas-docs/stable/timeseries.html的更多信息
这里是关于熊猫http://pandas.pydata.org/pandas-docs/stable/install.html的故事
https://stackoverflow.com/questions/20786538
复制相似问题