fork download
  1. import re
  2.  
  3. file = ['190.912.120.151 - skynet10001 [19/Jan/2012] "Temp"',
  4. '221.143.119.260 - terminator002 [16/Feb/2021] "Temp 2"']
  5. rx = re.compile(r'^(?P<IP>\d+(?:\.\d+){3})\s+\S+\s+(?P<Username>[a-z]+\d+)\s+\[(?P<Date>[^][]+)]\s+"(?P<Type>[^"]*)"')
  6.  
  7. def edata():
  8. results = []
  9. #with open("downloads/employeedata.txt", "r") as file:
  10. if not results: # this is just a stab, comment this line in real code, and uncomment the line above
  11. for line in file:
  12. match = rx.search(line)
  13. if match:
  14. results.append(match.groupdict())
  15. return results
  16.  
  17. print(edata())
Success #stdin #stdout 0.03s 9496KB
stdin
Standard input is empty
stdout
[{'IP': '190.912.120.151', 'Username': 'skynet10001', 'Date': '19/Jan/2012', 'Type': 'Temp'}, {'IP': '221.143.119.260', 'Username': 'terminator002', 'Date': '16/Feb/2021', 'Type': 'Temp 2'}]