0

I'm trying to dump VOIP SIP packets using pyshark and add them to pandas DataFrame. I need to add call info if it a new call or update of existing status

My code:

import pyshark
import pandas as pd

calls =  {}
columns = ['call_id','calldate','duration','provider','trunk','called_number','queue','sip_method','sip_status_code']
df = pd.DataFrame(columns = columns)

capture = pyshark.LiveCapture(interface='eth1', bpf_filter='udp port 5060')

for packet in capture.sniff_continuously():
  try:
    sip_method = packet['sip'].method
    call_id = packet['sip'].call_id
    calldate = "2021-03-31"
    provider = packet['sip'].r_uri_host
    called_number = packet['sip'].r_uri_user
    trunk = packet['sip'].contact_user
    queue = '9001'
    sip_status_code = packet['sip'].status_code

    if call_id in  df.index:
     print("UPDATING")
      df.loc[df.call_id == call_id ,['calldate','duration','provider','trunk','called_number','queue','sip_method','sip_status_code']] = ['2021-04-01',1,provider,trunk,called_number,'9001',sip_method,sip_status_code]
     print("UPDATED")
    else:
     print("INSERTING")
      df.at[call_id,['calldate','duration','provider','trunk','called_number','queue','sip_method','sip_status_code']]=['2021-04-01','0.2',provider,trunk,called_number,'9001',sip_method,sip_status_code]

    print(df)

Column 'call_id' is index New calls are added , but not updated.

harp1814
  • 1,494
  • 3
  • 13
  • 31

1 Answers1

0
for index, item in enumerate(df['call_id']):
     if call_id == index:
         .......
         .......

im not really understand, but if you want to get the the index number and try to match with the call_id, above the way. if you can explain more, will be good

que23
  • 25
  • 7