0

I have a dictionary that consists of 3 keys IP, Session_ID, Session_Length, the values are coming from multiple regexs like this:

regex_IP = re.compile('(?<![0-9])(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))(?![0-9])')
regex_req_sesslength = re.compile('([5-9]|\d\d\d*)\s[seconds]')
regex_high_sess = re.compile('(?P<sessionLength>[5-9]|\d{2,})(?= seconds)|(?<=relay_session )(?P<session_ID>\d+)(?= \(U)')

I have a file log file open and I want to search through the whole file, for a line with first, session_ID then session_length if found then session_ID with IP.

Here's what I reached so far https://repl.it/H9JR , sample text: https://pastebin.com/0EVjFRkL

I am open to recommendations of logic of course.

Update: I found this to be quite close to what I want to apply in my code: Match list values to dict and return key/value pairs in new dict

Trouble is when I do:

filtered_dict = {k: my_dict[k] for k in result3 if k in my_dict}
                  print (filtered_dict)

It only returns {} Nothing more..

Community
  • 1
  • 1
Ridah
  • 39
  • 8
  • What's the problem with your code? – Mazdak May 01 '17 at 07:40
  • No problem with the code, just trying to implement that last part of looping through the file if session_id found and session length met then find the matching ip of that session_id, all data are present in my dictionary so just that matching part from the dictionary to the open file. – Ridah May 01 '17 at 07:41

0 Answers0