Reputation: 13993
I have android app which sends the SMS from the mobile app which is as shown below:
my_dict = {\
u'1': u'"sender" : "dz-080008", "text" : "enjoy 10%[email protected] &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "shyam"', \
u'0': u'"sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "shyam"', \
u'3': u'"sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "shyam"', \
u'2': u'"sender" : "vx-611112", "text" : "we value your association with us. please call us on 89XXXXXXXX for exclusive offer onlyfor your number 88XXXXXXXX.u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "shyam"',\
}.
But I couldn't process the request and store it in my database because the app would send 100 sms in single request and by the time I process that request by extracting the key value pair other request would have come. So to overcome this I did store the request as it as in my database in each row.Each row contains a string as shown below:
<QueryDict: {u'messages': [u'<QueryDict: {u\'10\': [u\'"sender" : "md-dgenie", "text" : "your dudegenie code is 6326. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155575925", "name" : "p"\'], u\'1\': [u\'"sender" : "vm-olacab", "text" : "ola! your total bill for crn111085358 is rs 151. your invoice is on its way to your e-mail [email protected]. call us on 080-33553355 for any help.", "time" : "1439319374298", "name" : "p"\'], u\'0\': [u\'"sender" : "ad-hlpcht", "text" : "dear customer, 50% off on premium doorstep laundry. use the coupon code hc50. download the app now (bit.ly/help50chat) or give us a shout at 08039236390.", "time" : "1439356609276", "name" : "p"\'], u\'3\': [u\'"sender" : "vm-olacab", "text" : "say ola to your driver kiran m (8711045873) for crn111085358. silver tata indica ka 51 a 3940 to pick you up @ 12:06 am, 12aug. please share https://www.olacabs.com/track/939u1pe0m with friends/family and let them track you. call 080-33553355 if you need help.", "time" : "1439318029414", "name" : "p"\'], u\'2\': [u\'"sender" : "vm-olacab", "text" : "ola! your cab has arrived on time. hop on to have an awesome experience with this ride!", "time" : "1439318244463", "name" : "p"\'], u\'5\': [u\'"sender" : "dm-020001", "text" : "get upto 40%off +extra rs150 off@nykaa freedom sale with hdfc bank debit/credit card. code: nykhdfc150 .min purchasers1500. validity 15thaug *t&c bit.ly/1wedi4r", "time" : "1439300971524", "name" : "p"\'], u\'4\': [u\'"sender" : "dm-044210", "text" : "1 week to go!top 400 breeze mobile web transactors to get inr 250* flipkart vouchers/week & ipad mini*t&c apply.start now on.sc.com/breezedownload-in stanchart", "time" : "1439303662943", "name" : "p"\'], u\'7\': [u\'"sender" : "dz-080008", "text" : "enjoy 10%[email protected] &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 till 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "p"\'], u\'6\': [u\'"sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "p"\'], u\'9\': [u\'"sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "p"\'], u\'8\': [u\'"sender" : "vx-611112", "text" : "we value your association with us. please call us on 9739102435for exclusive offer onlyfor your number 889XXXXXXX .u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "p"\']}>']}>
Now what is best way to unpack this kind of unicode/string.?
Upvotes: 0
Views: 146
Reputation: 4043
I'm missing something? What are you trying to accomplish? What is the goal of the jsondem and ast imports?
Is this not sufficient for what you are trying to do ?
import json
my_dict = {u'1': u'"sender" : "dz-080008", "text" : "enjoy 10%[email protected] &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "shyam"', u'0': u'"sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "shyam"', \
u'3': u'"sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "shyam"', \
u'2': u'"sender" : "vx-611112", "text" : "we value your association with us. please call us on 89XXXXXXXX for exclusive offer onlyfor your number 88XXXXXXXX.u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "shyam"',\
}
for i in my_dict.values():
print json.dumps(i)
** output **
"\"sender\" : \"dz-080008\", \"text\" : \"enjoy 10%[email protected] &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 12aug-max amount rs1500 *t&c: bit.ly/1isljll\", \"time\" : \"1439212386383\", \"name\" : \"shyam\"" "sender" : "dz-080008", "text" : "enjoy 10%[email protected] &15%cashback@amazon app with hdfcbank debit/credit cards on min.purchase of rs5000 12aug-max amount rs1500 *t&c: bit.ly/1isljll", "time" : "1439212386383", "name" : "shyam" "\"sender\" : \"am-swiggy\", \"text\" : \"please use this otp: 195830\", \"time\" : \"1439226026974\", \"name\" : \"shyam\"" "sender" : "am-swiggy", "text" : "please use this otp: 195830", "time" : "1439226026974", "name" : "shyam" "\"sender\" : \"md-dgenie\", \"text\" : \"your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!\", \"time\" : \"1439155803426\", \"name\" : \"shyam\"" "sender" : "md-dgenie", "text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155803426", "name" : "shyam" "\"sender\" : \"vx-611112\", \"text\" : \"we value your association with us. please call us on 89XXXXXXXX for exclusive offer onlyfor your number 88XXXXXXXX.u can reach us from 10:00 am-06:00 pm\", \"time\" : \"1439191024750\", \"name\" : \"shyam\"" "sender" : "vx-611112", "text" : "we value your association with us. please call us on 89XXXXXXXX for exclusive offer onlyfor your number 88XXXXXXXX.u can reach us from 10:00 am-06:00 pm", "time" : "1439191024750", "name" : "shyam"
Upvotes: 0
Reputation: 1806
The strings are almost in dictionary format, but are not surrounded by {}. I think you want '{"sender" : "am-swiggy", ...}'
Upvotes: 1