Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. import re
  2. import datetime
  3. import pymssql
  4.  
  5.  
  6. server = "192.168.10.113"
  7. user ="sa"
  8. password ="vtm"
  9. conn = pymssql.connect(server, user, password, "vtm_cls")
  10. print("실행 %s"%(datetime.datetime.now()))
  11. cursor = conn.cursor()
  12.  
  13. S_StartEventTime = re.compile('StartTime:[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}')
  14. S_ENDEventTime = re.compile('StopTime:[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}')
  15. S_station = re.compile('Station:[0-9]*')
  16. S_Switch = re.compile('Switch:[0-9]*')
  17. S_Agent = re.compile('Agent:[0-9]*')
  18. S_CallID = re.compile('CallID:[0-9]*')
  19. S_CallIndex = re.compile('CallIndex:[0-9]*')
  20. S_PhoneNumber = re.compile('PhoneNumber:[0-9]*')
  21. S_Option1 = re.compile('Option1:[0-9]*')
  22. S_Option2 = re.compile('Option2:[0-9]*')
  23. S_Option3 = re.compile('Option3:[0-9]*')
  24. S_Option4 = re.compile('Option4:[0-9]*')
  25. S_Option5 = re.compile('Option5:[0-9]*')
  26. S_Option6 = re.compile('Option6:[0-9]*')
  27. S_Option7 = re.compile('Option7:[0-9]*')
  28. S_Option8 = re.compile('Option8:[0-9]*')
  29. S_Option9 = re.compile('Option9:[0-9]*')
  30. S_Option10 = re.compile('Option10:[0-9]*')
  31. S_Option11 = re.compile('Option11:[0-9]*')
  32. S_Option12 = re.compile('Option12:[0-9]*')
  33. S_Option13 = re.compile('Option13:[0-9]*')
  34. S_Option14 = re.compile('Option14:[0-9]*')
  35. S_Option15 = re.compile('Option15:[0-9]*')
  36. S_Option16 = re.compile('Option16:[0-9]*')
  37. S_Option17 = re.compile('Option17:[0-9]*')
  38. S_Option18 = re.compile('Option18:[0-9]*')
  39. S_Option19 = re.compile('Option19:[0-9]*')
  40. S_Option20 = re.compile('Option20:[0-9]*')
  41. S_logger = re.compile('Logger:[0-9]*')
  42. S_channel=re.compile('Channel:[0-9]*')
  43. S_Direction=re.compile('Direction:[a-z,A-Z]*')
  44. S_Status=re.compile('Status:[a-z,A-Z]*')
  45.  
  46. try:
  47. f=open('calllink_call_20150727.log','r')
  48. call=open('ServerCALL_%s.txt'%(datetime.datetime.now()), 'w')
  49. data=f.read()
  50. f.close()
  51. for line in data.strip().splitlines():
  52. if line.strip():
  53. ServerCALL = re.search('REPORTED',line)
  54. try:
  55. Start_Time = S_StartEventTime.search(line).group().split('StartTime:')[1]
  56. except:
  57. Start_Time = ''
  58.  
  59. try:
  60. Stop_Time = S_ENDEventTime.search(line).group().split('StopTime:')[1]
  61. except:
  62. Stop_Time = ''
  63.  
  64. try:
  65. Rec_Start_Time =S_StartEventTime.search(line).group().split('StartTime:')[1]
  66. except:
  67. Rec_Start_Time = ''
  68.  
  69. try:
  70. Duration = 0
  71. except:
  72. Duration = 0
  73.  
  74. try:
  75. Station = S_station.search(line).group().split(':')[1].split(',')[0]
  76. except:
  77. Station = ''
  78.  
  79. try:
  80. Trunk = ''
  81. except:
  82. Trunk = ''
  83.  
  84. try:
  85. Trunk_Label = ''
  86. except:
  87. Trunk_Label = ''
  88.  
  89. try:
  90. Direction =S_Direction.search(line).group().split(':')[1].split(',')[0]
  91. except:
  92. Direction = ''
  93.  
  94. try:
  95. Logger = S_logger.search(line).group().split(':')[1]
  96. except:
  97. Logger = 0
  98.  
  99. try:
  100. Channel = S_channel.search(line).group().split(':')[1]
  101. except:
  102. Channel = 0
  103.  
  104. try:
  105. Agent_ID = S_Agent.search(line).group().split(':')[1]
  106. except:
  107. Agent_ID = 0
  108.  
  109. try:
  110. Agent_Name = ''
  111. except:
  112. Agent_Name = ''
  113.  
  114. try:
  115. UserID = 0
  116. except:
  117. UserID = 0
  118.  
  119. try:
  120. Comment = ''
  121. except:
  122. Comment = ''
  123.  
  124. try:
  125. Flags = 0
  126. except:
  127. Flags = 0
  128.  
  129. try:
  130. Status = S_Status.search(line).group().split(':')[1].split(',')[0]
  131. except:
  132. Status = ''
  133.  
  134. try:
  135. Unit = 0
  136. except:
  137. Unit = 0
  138.  
  139. try:
  140. Phone_Number = S_PhoneNumber.search(line).group().split(':')[1]
  141. except:
  142. Phone_Number = ''
  143.  
  144. try:
  145. Dialed_In = ''
  146. except:
  147. Dialed_In = ''
  148.  
  149. try:
  150. Call_ID = S_CallID.search(line).group().split(':')[1]
  151. except:
  152. Call_ID = 0
  153.  
  154. try:
  155. # Call_Index = S_CallIndex.search(line).group().split(':')[1]
  156. Call_Index = 0
  157. except:
  158. Call_Index = 0
  159.  
  160. try:
  161. Device = ''
  162. except:
  163. Device = ''
  164.  
  165. try:
  166. Department = ''
  167. except:
  168. Department = ''
  169.  
  170. try:
  171. Cls_Call_Id = 0
  172. except:
  173. Cls_Call_Id = 0
  174.  
  175. try:
  176. Locked = ''
  177. except:
  178. Locked = ''
  179.  
  180. try:
  181. QA = 0
  182. except:
  183. QA = 0
  184.  
  185. try:
  186. QA_Program = ''
  187. except:
  188. QA_Program = ''
  189.  
  190. try:
  191. Rec_Program = ''
  192. except:
  193. Rec_Program = ''
  194.  
  195. try:
  196. Rec_Initiator = ''
  197. except:
  198. Rec_Initiator = ''
  199.  
  200. try:
  201. Evaluated = 0
  202. except:
  203. Evaluated = 0
  204.  
  205. try:
  206. Recorded = ''
  207. except:
  208. Recorded = ''
  209.  
  210. try:
  211. CompoundID = 0
  212. except:
  213. CompoundID = 0
  214.  
  215. try:
  216. Optional1 = S_Option1.search(line).group().split(':')[1]
  217. except:
  218. Optional1 = ''
  219. try:
  220. Optional2 = S_Option2.search(line).group().split(':')[1]
  221. except:
  222. Optional2 = ''
  223.  
  224. try:
  225. Optional3 = S_Option3.search(line).group().split(':')[1]
  226. except:
  227. Optional3 = ''
  228.  
  229. try:
  230. Optional4 = S_Option4.search(line).group().split(':')[1]
  231. except:
  232. Optional4 = ''
  233.  
  234. try:
  235. Optional5 = S_Option5.search(line).group().split(':')[1]
  236. except:
  237. Optional5 = ''
  238.  
  239. try:
  240. Optional6 = S_Option6.search(line).group().split(':')[1]
  241. except:
  242. Optional6 = ''
  243.  
  244. try:
  245. Optional7 = S_Option7.search(line).group().split(':')[1]
  246. except:
  247. Optional7 = ''
  248.  
  249. try:
  250. Optional8 = S_Option8.search(line).group().split(':')[1]
  251. except:
  252. Optional8 = ''
  253.  
  254. try:
  255. Optional9 = S_Option9.search(line).group().split(':')[1]
  256. except:
  257. Optional9 = ''
  258.  
  259. try:
  260. Optional10 = S_Option10.search(line).group().split(':')[1]
  261. except:
  262. Optional10 = ''
  263.  
  264. try:
  265. Optional11 = S_Option11.search(line).group().split(':')[1]
  266. except:
  267. Optional11 = ''
  268.  
  269. try:
  270. Optional12 = S_Option12.search(line).group().split(':')[1]
  271. except:
  272. Optional12 = ''
  273.  
  274. try:
  275. Optional13 = S_Option13.search(line).group().split(':')[1]
  276. except:
  277. Optional13 = ''
  278.  
  279. try:
  280. Optional14 = S_Option14.search(line).group().split(':')[1]
  281. except:
  282. Optional14 = ''
  283.  
  284. try:
  285. Optional15 = S_Option15.search(line).group().split(':')[1]
  286. except:
  287. Optional15 = ''
  288.  
  289. try:
  290. Optional16 = S_Option16.search(line).group().split(':')[1]
  291. except:
  292. Optional16 = ''
  293.  
  294. try:
  295. Optional17 = ''
  296. except:
  297. Optional17 = S_Option17.search(line).group().split(':')[1]
  298.  
  299. try:
  300. Optional18 = ''
  301. except:
  302. Optional18 = S_Option18.search(line).group().split(':')[1]
  303.  
  304. try:
  305. Optional19 = ''
  306. except:
  307. Optional19 = S_Option19.search(line).group().split(':')[1]
  308.  
  309. try:
  310. Optional20 = ''
  311. except:
  312. Optional20 = S_Option20.search(line).group().split(':')[1]
  313.  
  314. try:
  315. TagStartTime = ''
  316. except:
  317. TagStartTime = ''
  318.  
  319. try:
  320. TagEndTime = ''
  321. except:
  322. TagEndTime = ''
  323.  
  324. try:
  325. TagStartTime2 = ''
  326. except:
  327. TagStartTime2 = ''
  328.  
  329. try:
  330. TagEndTime2 = ''
  331. except:
  332. TagEndTime2 = ''
  333.  
  334. try:
  335. TagStartTime3 = ''
  336. except:
  337. TagStartTime3 = ''
  338.  
  339. try:
  340. TagEndTime3 = ''
  341. except:
  342. TagEndTime3 = ''
  343.  
  344. try:
  345. EvaluatorID = 0
  346. except:
  347. EvaluatorID = 0
  348.  
  349. try:
  350. StoragePath = ''
  351. except:
  352. StoragePath = ''
  353.  
  354. try:
  355. nDiskSpaceSize = ''
  356. except:
  357. nDiskSpaceSize = ''
  358.  
  359. try:
  360. StorageName = ''
  361. except:
  362. StorageName = ''
  363.  
  364. try:
  365. cSLAVIPath = ''
  366. except:
  367. cSLAVIPath = ''
  368.  
  369. try:
  370. iSLID = 0
  371. except:
  372. iSLID = 0
  373.  
  374. try:
  375. iSLAVIExist = 0
  376. except:
  377. iSLAVIExist = 0
  378.  
  379. try:
  380. cslstoragepath = ''
  381. except:
  382. cslstoragepath = ''
  383.  
  384. try:
  385. cSLStorageName = ''
  386. except:
  387. cSLStorageName = ''
  388.  
  389. try:
  390. iSLDiskSpaceSize = 0
  391. except:
  392. iSLDiskSpaceSize = 0
  393.  
  394. try:
  395. iSLFlags = 0
  396. except:
  397. iSLFlags = 0
  398.  
  399. if ServerCALL:
  400. call.write(line + "\n")
  401. cursor.execute("""
  402. INSERT INTO vtm_cls.dbo.CALL_0081
  403. (Start_Time, Stop_Time, Rec_Start_Time, Duration, Station, Trunk, Trunk_Label, Direction, Logger, Channel, Agent_ID, Agent_Name, UserID, Comment, Flags, Status, Unit, Phone_Number, Dialed_In, Call_ID, Call_Index, Device, Department, Cls_Call_Id, Locked, QA, QA_Program, Rec_Program, Rec_Initiator, Evaluated, Recorded, CompoundID, Optional1, Optional2, Optional3, Optional4, Optional5, Optional6, Optional7, Optional8, Optional9, Optional10, Optional11, Optional12, Optional13, Optional14, Optional15, Optional16, Optional17, Optional18, Optional19, Optional20, TagStartTime, TagEndTime, TagStartTime2, TagEndTime2, TagStartTime3, TagEndTime3, EvaluatorID, StoragePath, nDiskSpaceSize, StorageName, cSLAVIPath, iSLID, iSLAVIExist, cslstoragepath, cSLStorageName, iSLDiskSpaceSize, iSLFlags)
  404. VALUES(%(start_time)s,%(stop_Time)s, %(rec_start_time)s, %(duration)d, %(station)s, %(trunk)s, %(trunk_label)s, %(direction)s, %(logger)d, %(channel)d, %(agent_id)d, %(agent_name)s, %(userid)d, %(comment)s, %(flags)s, %(status)s, %(unit)d, %(phone_number)s, %(dialed_in)s, %(call_id)d, %(call_index)d, %(device)s, %(department)s, %(cls_call_id)d, %(locked)s, %(qa)d, %(qa_program)s, %(rec_program)s, %(rec_initiator)s, %(evaluated)d, %(recorded)s, %(compoundid)d, %(optional1)s, %(optional2)s, %(optional3)s, %(optional4)s, %(optional5)s, %(optional6)s, %(optional7)s, %(optional8)s, %(optional9)s, %(optional10)s, %(optional11)s, %(optional12)s, %(optional13)s, %(optional14)s, %(optional15)s, %(optional16)s, %(optional17)s, %(optional18)s, %(optional19)s, %(optional20)s, %(tagstarttime)s, %(tagendtime)s, %(tagstarttime2)s, %(tagendtime2)s, %(tagstarttime3)s, %(tagendtime3)s, %(evaluatorid)d, %(storagepath)s,%(ndiskspacesize)d,%(storagename)s,%(cslavipath)s,%(islid)d,%(islaviexist)d, %(Cslstoragepath)s,%(cslstoragename)s,%(isldiskspacesize)d, %(islflags)d);
  405. """, {'start_time': Start_Time, 'stop_Time': Stop_Time, 'rec_start_time': Rec_Start_Time,
  406. 'duration': Duration, 'station': Station, 'trunk': Trunk, 'trunk_label': Trunk_Label,
  407. 'direction': Direction, 'logger': Logger, 'channel': Channel, 'agent_id': Agent_ID,
  408. 'agent_name': Agent_Name, 'userid': UserID, 'comment': Comment, 'flags': Flags,
  409. 'status': Status, 'unit': Unit, 'phone_number': Phone_Number, 'dialed_in': Dialed_In,
  410. 'call_id': Call_ID, 'call_index': Call_Index, 'device': Device,
  411. 'department': Department, 'cls_call_id': Cls_Call_Id, 'locked': Locked, 'qa': QA,
  412. 'qa_program': QA_Program, 'rec_program': Rec_Program, 'rec_initiator': Rec_Initiator,
  413. 'evaluated': Evaluated, 'recorded': Recorded, 'compoundid': CompoundID,
  414. 'optional1': Optional1, 'optional2': Optional2, 'optional3': Optional3,
  415. 'optional4': Optional4, 'optional5': Optional5, 'optional6': Optional6,
  416. 'optional7': Optional7, 'optional8': Optional8, 'optional9': Optional9,
  417. 'optional10': Optional10, 'optional11': Optional11, 'optional12': Optional12,
  418. 'optional13': Optional13, 'optional14': Optional14, 'optional15': Optional15,
  419. 'optional16': Optional16, 'optional17': Optional17, 'optional18': Optional18,
  420. 'optional19': Optional19, 'optional20': Optional20, 'tagstarttime': TagStartTime,
  421. 'tagendtime': TagEndTime, 'tagstarttime2': TagStartTime2, 'tagendtime2': TagEndTime2,
  422. 'tagstarttime3': TagStartTime3, 'tagendtime3': TagEndTime3,
  423. 'evaluatorid': EvaluatorID, 'storagepath': StoragePath,
  424. 'ndiskspacesize': nDiskSpaceSize, 'storagename': StorageName,
  425. 'cslavipath': cSLAVIPath, 'islid': iSLID, 'islaviexist': iSLAVIExist,
  426. 'Cslstoragepath': cslstoragepath, 'cslstoragename': cSLStorageName,
  427. 'isldiskspacesize': iSLDiskSpaceSize, 'islflags': iSLFlags})
  428. conn.commit()
  429.  
  430. else:
  431. continue
  432.  
  433. finally:
  434. cursor.execute("""UPDATE vtm_cls.dbo.CALL_0081 SET [Duration]=DATEDIFF(ss,[Start_Time],[Stop_Time])""")
  435. conn.commit()
  436.  
  437. call.close()
  438. conn.close()
  439. print("완료 %s"%(datetime.datetime.now()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement