def query_db(query, args=(), one=False):
cur = connection.cursor()
cur.execute(query, args)
r = [dict((cur.description[i][0], value)
for i, value in enumerate(row)) for row in cur.fetchall()]
cur.connection.close()
return (r[0] if r else None) if one else r
my_query = query_db("select top 1 email as email_address,status = 'subscribed',firstname,lasstname from users")
json_output = json.dumps(my_query)
print json_output
Result is this:
[{
"status": "subscribed",
"lastname": "Engineer",
"email": "theengineer@yahoo.com",
"firstname": "The"}]
what I want is this
{
"email_address":"yash@yahoo.com",
"status":"subscribed",
'merge_fields': {
'firstname': 'yash',
'lastname': 'chakka',
}
I don't have any column called merge-fields in database but, I want this merge-fields header for every email-id with first name and last name under it to post it to Mailchimp. what modification do i have to do to my cursor get desired output. Any help will be appreciated. Thanks!