I am using the following code to extract data from Salesforce using beatbox python API.
import beatbox
sf_username = "[email protected]"
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, 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
Here is an example:
records is a list of dictionaries as you mentioned before
Now you have table-style Dataframe object. You can index multiple columns and rows:
Here is more about pandas time functionality http://pandas.pydata.org/pandas-docs/stable/timeseries.html
And here is about pandas http://pandas.pydata.org/pandas-docs/stable/install.html