fork download
  1. import re
  2. import datetime
  3. import sys
  4.  
  5. date_format = '[%d/%b/%Y:%H:%M:%S %z]'
  6.  
  7. date_regexp = re.compile('\[.+\]')
  8.  
  9. #with open('apache.out', 'w', encoding='cp1251') as out:
  10. # with open('apache.in', 'r', encoding='cp1251') as file:
  11. file = sys.stdin
  12. out = sys.stdout
  13. tz = datetime.datetime.strptime(file.readline(), '%z\n')
  14. for line in file:
  15. date = datetime.datetime.strptime(date_regexp.search(line)[0], date_format)
  16. out.write(date_regexp.sub(date.astimezone(tz.tzinfo).strftime(date_format), line))
  17.  
Runtime error #stdin #stdout #stderr 0.02s 28696KB
stdin
-0200
195.19.224.104 - abc [02/Dec/2004:18:25:19 +0100] "GET / HTTP/1.1" 304 -
195.19.224.104 - - [02/Dec/2004:18:25:19 +0100] "GET /main.css HTTP/1.1" 304 -
195.19.224.79 - - [02/Dec/2004:20:58:20 +0300] "GET /tts HTTP/1.1" 302 293
195.19.224.79 - - [02/Dec/2004:20:58:20 +0300] "GET /tts/ HTTP/1.1" 302 303
207.46.98.42 - - [03/Dec/2004:04:39:32 +0300] "GET /robots.txt HTTP/1.0"
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 15, in <module>
    date = datetime.datetime.strptime(date_regexp.search(line)[0], date_format)
TypeError: '_sre.SRE_Match' object is not subscriptable