callerid.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import pythoncom, time
  2. import win32com.client
  3. import subprocess
  4. cls="TAPI.TAPI"
  5. # need for gen_py
  6. ti = win32com.client.Dispatch(cls)._oleobj_.GetTypeInfo()
  7. tlb, index = ti.GetContainingTypeLib()
  8. tla = tlb.GetLibAttr()
  9. win32com.client.gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0)
  10. tapi=win32com.client.Dispatch(cls)
  11. tapi.Initialize() # must run after Dispatch and before TapiEvents
  12. class TapiEvents(win32com.client.getevents(cls)):
  13. def OnEvent(self, ev1,ev2):
  14. constants = win32com.client.constants
  15. if ev1 == constants.TE_CALLNOTIFICATION:
  16. call = win32com.client.Dispatch(ev2).Call
  17. try:
  18. print_check_error(f"CIS_CALLEDIDNAME", call, constants.CIS_CALLEDIDNAME)
  19. print_check_error(f"CIS_CALLERIDNUMBER", call, constants.CIS_CALLERIDNUMBER)
  20. print_check_error(f"CIS_CALLEDIDNUMBER", call, constants.CIS_CALLEDIDNUMBER)
  21. print_check_error(f"CIS_CONNECTEDIDNAME", call, constants.CIS_CONNECTEDIDNAME)
  22. print_check_error(f"CIS_CONNECTEDIDNUMBER", call, constants.CIS_CONNECTEDIDNUMBER)
  23. print_check_error(f"CIS_REDIRECTIONIDNAME", call, constants.CIS_REDIRECTIONIDNAME)
  24. print_check_error(f"CIS_REDIRECTIONIDNUMBER", call, constants.CIS_REDIRECTIONIDNUMBER)
  25. print_check_error(f"CIS_REDIRECTINGIDNAME", call, constants.CIS_REDIRECTINGIDNAME)
  26. print_check_error(f"CIS_REDIRECTINGIDNUMBER", call, constants.CIS_REDIRECTINGIDNUMBER)
  27. print_check_error(f"CIS_CALLEDPARTYFRIENDLYNAME", call, constants.CIS_CALLEDPARTYFRIENDLYNAME)
  28. print_check_error(f"CIS_COMMENT", call, constants.CIS_COMMENT)
  29. print_check_error(f"CIS_DISPLAYABLEADDRESS", call, constants.CIS_DISPLAYABLEADDRESS)
  30. print_check_error(f"CIS_CALLINGPARTYID", call, constants.CIS_CALLINGPARTYID)
  31. except:
  32. pass
  33. events=TapiEvents(tapi)
  34. tapi.EventFilter = 0x1FFFF
  35. for item in tapi.Addresses: ext = item.AddressName.split(' ',)[0]
  36. def counter():
  37. if not hasattr(counter, "counter"):
  38. counter.counter = 0 # it doesn't exist yet, so initialize it
  39. counter.counter += 1
  40. def print_check_error(str, obj, code):
  41. try:
  42. output = obj.CallInfoString(code)
  43. if bool(output):
  44. if (code == 1) and (len(output) > len(ext) ) :
  45. counter()
  46. if counter.counter % 2 == 0 :
  47. print(f"Ouvrir fiche du {output}")
  48. command = f".\\navista.exe {output} nom https://api.navista/"
  49. subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
  50. else :
  51. print(f"Appel entrant de {output}")
  52. except:
  53. pass
  54. for addr in tapi.Addresses:
  55. try:
  56. tapi.RegisterCallNotifications(addr,True,True,8,0)
  57. except:
  58. pass
  59. try:
  60. while True:
  61. pythoncom.PumpWaitingMessages()
  62. time.sleep(0.01) # Don't use up all our CPU checking constantly
  63. except KeyboardInterrupt:
  64. pass