Skip to content

Instantly share code, notes, and snippets.

@nenodias
Last active September 9, 2016 01:27
Show Gist options
  • Save nenodias/4edee5cd4a3f945b6b24bf98a6b8599b to your computer and use it in GitHub Desktop.
Save nenodias/4edee5cd4a3f945b6b24bf98a6b8599b to your computer and use it in GitHub Desktop.
Desafio
IDX_IP = 0
IDX_DATA_HORA = 3
IDX_METODO = 5
IDX_URL = 6
IDX_STATUS = 8
IDX_TAMANHO = 9
with open('log.txt', 'r') as f:
conteudo = f.read()
for linha in conteudo.split('\n'):
dados = linha.split()
ip = dados[IDX_IP]
data_hora = dados[IDX_DATA_HORA][1:]
data = data_hora[:11]
hora = data_hora[12:]
metodo = dados[IDX_METODO][1:]
url = dados[IDX_URL]
status = dados[IDX_STATUS]
tamanho = dados[IDX_TAMANHO]
print('-'*80)
print('Data %s'%(data))
print('Hora %s'%(hora))
print('IP %s'%(ip))
print('Metodo %s'%(metodo))
print('Caminho %s'%(url))
print('Resposta %s'%(status))
print('Tamanho %s'%(tamanho))
print('-'*80)
Utilize o log acima para apresentar essas informações de forma mais amigavel, algo parecido com o exemplo abaixo
----------------------------------------------------------------------------------------------------
Data 07/Mar/2004
Hora 16:05:49
IP 64.242.88.10
Metodo GET
Caminho /twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables
Resposta 401
Tamanho 12846
----------------------------------------------------------------------------------------------------
Boa sorte!!
64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET /twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12846
64.242.88.10 - - [07/Mar/2004:16:06:51 -0800] "GET /twiki/bin/rdiff/TWiki/NewUserTemplate?rev1=1.3&rev2=1.2 HTTP/1.1" 200 4523
64.242.88.10 - - [07/Mar/2004:16:10:02 -0800] "GET /mailman/listinfo/hsdivision HTTP/1.1" 200 6291
64.242.88.10 - - [07/Mar/2004:16:11:58 -0800] "GET /twiki/bin/view/TWiki/WikiSyntax HTTP/1.1" 200 7352
64.242.88.10 - - [07/Mar/2004:16:20:55 -0800] "GET /twiki/bin/view/Main/DCCAndPostFix HTTP/1.1" 200 5253
64.242.88.10 - - [07/Mar/2004:16:23:12 -0800] "GET /twiki/bin/oops/TWiki/AppendixFileSystem?template=oopsmore¶m1=1.12¶m2=1.12 HTTP/1.1" 200 11382
64.242.88.10 - - [07/Mar/2004:16:24:16 -0800] "GET /twiki/bin/view/Main/PeterThoeny HTTP/1.1" 200 4924
64.242.88.10 - - [07/Mar/2004:16:29:16 -0800] "GET /twiki/bin/edit/Main/Header_checks?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12851
64.242.88.10 - - [07/Mar/2004:16:30:29 -0800] "GET /twiki/bin/attach/Main/OfficeLocations HTTP/1.1" 401 12851
64.242.88.10 - - [07/Mar/2004:16:31:48 -0800] "GET /twiki/bin/view/TWiki/WebTopicEditTemplate HTTP/1.1" 200 3732
64.242.88.10 - - [07/Mar/2004:16:32:50 -0800] "GET /twiki/bin/view/Main/WebChanges HTTP/1.1" 200 40520
64.242.88.10 - - [07/Mar/2004:16:33:53 -0800] "GET /twiki/bin/edit/Main/Smtpd_etrn_restrictions?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12851
64.242.88.10 - - [07/Mar/2004:16:35:19 -0800] "GET /mailman/listinfo/business HTTP/1.1" 200 6379
64.242.88.10 - - [07/Mar/2004:16:36:22 -0800] "GET /twiki/bin/rdiff/Main/WebIndex?rev1=1.2&rev2=1.1 HTTP/1.1" 200 46373
64.242.88.10 - - [07/Mar/2004:16:37:27 -0800] "GET /twiki/bin/view/TWiki/DontNotify HTTP/1.1" 200 4140
64.242.88.10 - - [07/Mar/2004:16:39:24 -0800] "GET /twiki/bin/view/Main/TokyoOffice HTTP/1.1" 200 3853
64.242.88.10 - - [07/Mar/2004:16:43:54 -0800] "GET /twiki/bin/view/Main/MikeMannix HTTP/1.1" 200 3686
64.242.88.10 - - [07/Mar/2004:16:45:56 -0800] "GET /twiki/bin/attach/Main/PostfixCommands HTTP/1.1" 401 12846
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment