【发布时间】:2022-07-27 23:19:15
【问题描述】:
我正在接收这个字符串字典作为 API 响应,它将进一步用作另一个任务的输入。
{' cAVDNIIB ': ' pattern not matched: "[2022-07-25 06:40:51.147] [Information] LW () <RDP> Bot execution completed - JOBNAME:\\"TEST_NAME_1\\" JOBID:\\"2022072564027\\" TYPE:\\"Desktop\\" startTime:\\"1658731228\\" endTime:\\"1658731251\\" botMachineName:\\"LW\\" botMachineIP:\\"SOME_IP\\" state:\\"completed\\" status:\\"successful\\" Action:\\"run\\"" ',
' cQVDNIIB ': ' pattern not matched: "[2022-07-25 07:30:11.711] [Information] LW () <RDP> Bot consumer listening for messages." ',
' cgVDNIIB ': ' pattern not matched: "[2022-07-25 07:30:11.714] [Information] LW () <RDP> Message received from queue - JOBNAME:\\"TEST_NAME\\" JOBID:\\"2022072573011\\" TYPE:\\"Desktop\\" startTime:\\"1658734211\\" Action:\\"run\\"" ',
' cwVDNIIB ': ' pattern not matched: "[2022-07-25 07:30:11.717] [Information] LW () <RDP> Bot action:\\"run\\"" ',
' dAVDNIIB ': ' pattern not matched: "[2022-07-25 07:30:11.717] [Information] LW () <RDP> [x] \\"{\\\\\\"JOBNAME\\\\\\":\\\\\\"TEST_NAME\\\\\\",\\\\\\"TYPE\\\\\\":\\\\\\"Desktop\\\\\\",\\\\\\"rdpRequired\\\\\\":false,\\\\\\"state\\\\\\":\\\\\\"Running\\\\\\",\\\\\\"status\\\\\\":\\\\\\"Running\\\\\\",\\\\\\"requestorId\\\\\\":null,\\\\\\"JOBID\\\\\\":\\\\\\"2022072573011\\\\\\",\\\\\\"startTime\\\\\\":null,\\\\\\"endTime\\\\\\":null,\\\\\\"botstatus\\\\\\":null,\\\\\\"action\\\\\\":\\\\\\"run\\\\\\"}\\"" ',
' dQVDNIIB ': ' pattern not matched: "[2022-07-25 07:30:11.718] [Information] LW () <RDP> Creating background process \'\\"C:\\\\Tools\\\\Flows\\\\Desktop\\\\TEST_NAME\\\\Simulator.exe\\"\'" ',
' gQVENIIB ': ' pattern not matched: "[2022-07-25 07:30:11.743] [Information] LW () <RDP> Bot execution started - JOBNAME:\\"TEST_NAME\\" JOBID:\\"2022072573011\\" TYPE:\\"Desktop\\" startTime:\\"1658734211\\" botMachineName:\\"LW\\" botMachineIP:\\"SOME_IP\\" state:\\"Running\\" status:\\"Running\\" Action:\\"run\\"" ',
' ggVENIIB ': ' pattern not matched: "[2022-07-25 07:31:23.368] [Information] LW () <RDP> Published message to response queue: ExchangeName:\\"liteportal.exchange\\", Message:\\"{\\\\\\"requestorId\\\\\\":null,\\\\\\"rdpRequired\\\\\\":false,\\\\\\"JOBNAME\\\\\\":\\\\\\"TEST_NAME\\\\\\",\\\\\\"JOBID\\\\\\":\\\\\\"2022072573011\\\\\\",\\\\\\"TYPE\\\\\\":\\\\\\"Desktop\\\\\\",\\\\\\"startTime\\\\\\":\\\\\\"1658734211\\\\\\",\\\\\\"endTime\\\\\\":\\\\\\"1658734283\\\\\\",\\\\\\"status\\\\\\":\\\\\\"successful\\\\\\",\\\\\\"action\\\\\\":\\\\\\"run\\\\\\",\\\\\\"state\\\\\\":\\\\\\"completed\\\\\\",\\\\\\"botMachineName\\\\\\":\\\\\\"LW\\\\\\",\\\\\\"botMachineOS\\\\\\":\\\\\\"WindowsXP 6.2.9200.0\\\\\\",\\\\\\"botMachineIP\\\\\\":\\\\\\"SOME_IP\\\\\\",\\\\\\"Message\\\\\\":null}\\" " ',
' gwVENIIB ': ' pattern not matched: "[2022-07-25 07:31:23.373] [Information] LW () <RDP> Log file path: \\"C:\\\\Tools\\\\Flows\\\\Desktop\\\\TEST_NAME\\\\logs\\\\Logs-2022_07_25.log\\"" ',
' hAVENIIB ': ' pattern not matched: "[2022-07-25 07:31:23.374] [Information] LW () <RDP> Log file exists" ',
' hgVENIIB ': ' pattern not matched: "[2022-07-25 07:31:23.384] [Information] LW () <RDP> Bot log file deleted: \\"C:\\\\Tools\\\\Flows\\\\Desktop\\\\TEST_NAME\\\\logs\\\\Logs-2022_07_25.log\\"" '}
需要将此输入转换为只有具有所有这些值的数据帧:
| jobid | jobname | type | startTime | endTime | state | status |
|---|---|---|---|---|---|---|
| 2022072564027 | TEST_NAME_1 | Desktop | 1658731228 | 1658731251 | completed | successful |
| 2022072573011 | TEST_NAME | Desktop | 1658734211 | 1658734283 | completed | successful |
尝试解析键值以删除特殊字符和反斜杠,还尝试使用正则表达式提取所需的匹配项,但无法通过每次迭代运行正确的匹配项。
请分享您的想法并提出 Python 中的最佳解决方案? 谢谢你的帮助!!
【问题讨论】: