How to split value where is comma ?

28 views
Skip to first unread message

Asad ur Rehman

unread,
Sep 7, 2016, 11:50:08 AM9/7/16
to Django users
Here is my view.py

import os.path
import commands

def call_report(request):
 
    a = commands.getstatusoutput('/usr/local/freeswitch/bin/fs_cli -x "show calls"')
    return HttpResponse(a)


When i run this command it gives output which you can see...


0uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,hostname,sent_callee_name,sent_callee_num,b_uuid,b_direction,b_created,b_created_epoch,b_name,b_state,b_cid_name,b_cid_num,b_ip_addr,b_dest,b_presence_id,b_presence_data,b_callstate,b_callee_name,b_callee_num,b_callee_direction,b_sent_callee_name,b_sent_callee_num,call_created_epoch 7135c05c-7511-11e6-a09e-89a1f4981d2c,outbound,2016-09-07 11:40:45,1473262845,sofia/external/12036325207,CS_EXECUTE,Outbound Call,12036325207,,12036325207,,,ACTIVE,9047125683,9047125683,RECV,7135c05c-7511-11e6-a09e-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 75a9d3ee-7511-11e6-a115-89a1f4981d2c,outbound,2016-09-07 11:40:53,1473262853,sofia/external/12036325259,CS_EXECUTE,Outbound Call,12036325259,,12036325259,,,ACTIVE,9047125683,9047125683,RECV,75a9d3ee-7511-11e6-a115-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7841c6c0-7511-11e6-a139-89a1f4981d2c,outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135,CS_EXECUTE,Outbound Call,16189973135,,16189973135,,,ACTIVE,3473788006,3473788006,RECV,7841c6c0-7511-11e6-a139-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 78582a82-7511-11e6-a141-89a1f4981d2c,outbound,2016-09-07 11:40:57,1473262857,sofia/external/16185392123,CS_EXECUTE,Outbound Call,16185392123,,16185392123,,,ACTIVE,3473788006,3473788006,RECV,78582a82-7511-11e6-a141-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 79eda1ec-7511-11e6-a161-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/12037584114,CS_EXECUTE,Outbound Call,12037584114,,12037584114,,,ACTIVE,3473788006,3473788006,RECV,79eda1ec-7511-11e6-a161-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a02bb90-7511-11e6-a169-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/13346775290,CS_EXECUTE,Outbound Call,13346775290,,13346775290,,,ACTIVE,3473788006,3473788006,RECV,7a02bb90-7511-11e6-a169-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a1fa002-7511-11e6-a179-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/15154483189,CS_EXECUTE,Outbound Call,15154483189,,15154483189,,,ACTIVE,3473788006,3473788006,RECV,7a1fa002-7511-11e6-a179-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a20d864-7511-11e6-a181-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/12036325257,CS_EXECUTE,Outbound Call,12036325257,,12036325257,,,ACTIVE,9047125683,9047125683,RECV,7a20d864-7511-11e6-a181-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7a354cf4-7511-11e6-a191-89a1f4981d2c,outbound,2016-09-07 11:41:00,1473262860,sofia/external/13348725798,CS_EXECUTE,Outbound Call,13348725798,,13348725798,,,ACTIVE,9047125683,9047125683,RECV,7a354cf4-7511-11e6-a191-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7e90e128-7511-11e6-a1d4-89a1f4981d2c,outbound,2016-09-07 11:41:07,1473262867,sofia/external/13345880337,CS_EXECUTE,Outbound Call,13345880337,,13345880337,,,ACTIVE,9047125683,9047125683,RECV,7e90e128-7511-11e6-a1d4-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7e9c3514-7511-11e6-a1e8-89a1f4981d2c,outbound,2016-09-07 11:41:08,1473262868,sofia/external/12036325256,CS_EXECUTE,Outbound Call,12036325256,,12036325256,,,ACTIVE,9047125683,9047125683,RECV,7e9c3514-7511-11e6-a1e8-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 7f3cdc62-7511-11e6-a1ff-89a1f4981d2c,outbound,2016-09-07 11:41:09,1473262869,sofia/external/13344992844,CS_EXECUTE,Outbound Call,13344992844,,13344992844,,,ACTIVE,9047125683,9047125683,RECV,7f3cdc62-7511-11e6-a1ff-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 82179454-7511-11e6-a228-89a1f4981d2c,outbound,2016-09-07 11:41:13,1473262873,sofia/external/16185392157,CS_EXECUTE,Outbound 


But i want to get output like this


0uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,hostname,sent_callee_name,sent_callee_num,b_uuid,b_direction,b_created,b_created_epoch,b_name,b_state,b_cid_name,b_cid_num,b_ip_addr,b_dest,b_presence_id,b_presence_data,b_callstate,b_callee_name,b_callee_num,b_callee_direction,b_sent_callee_name,b_sent_callee_num,call_created_epoch 7135c05c-7511-11e6-a09e-89a1f4981d2c,outbound,2016-09-07 11:40:45,1473262845,sofia/external/12036325207,CS_EXECUTE,Outbound Call,12036325207,,12036325207,,,ACTIVE,9047125683,9047125683,RECV,7135c05c-7511-11e6-a09e-89a1f4981d2c,vb-pmedia,,,,,,,,,,,,,,,,,,,,, 75a9d3ee-7511-11e6-a115-89a1f4981d2c,outbound,2016-09-07 11:40:53,
1473262853,
sofia/external/1203632525,CS_EXECUTE,
Outbound Call,
,
,ACTIVE,
RECV,
75a9d3ee-7511-11e6-a115-89a1f4981d2c,
vb-pmedia,,,,,,,,,,,,,,,,,,,,,7841c6c0-7511-11e6-a139-89a1f4981d2c,
 outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135,



where is a comma there should start new line ... How can i do it ?

Thanks in advance !



ludovic coues

unread,
Sep 7, 2016, 12:03:33 PM9/7/16
to django...@googlegroups.com
That look a lot like a csv file. I strongly suggest you take a look at
[1] and [2]. It should let you work with your data as if it's a list
of dict. Pretty handy.

If all you want is to add a newline after each comma, I suggest to use replace.
>>> print("1,2,3".replace(",", ",\n"))
1,
2,
3

[1] https://docs.python.org/3/library/csv.html#csv.DictReader
[2] https://docs.python.org/3/library/io.html#io.StringIO
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/804fc61c-9282-43ac-9e42-17b885061e2e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages