Skip to content

Instantly share code, notes, and snippets.

@sly01
Created May 21, 2022 14:16
Show Gist options
  • Save sly01/53830ca2d3f865b96b3aa64dfc11d20b to your computer and use it in GitHub Desktop.
Save sly01/53830ca2d3f865b96b3aa64dfc11d20b to your computer and use it in GitHub Desktop.

Revisions

  1. sly01 created this gist May 21, 2022.
    26 changes: 26 additions & 0 deletions codeexample.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import re

    f = open("data.csv", "r")
    lines = f.readlines()

    regex = '\[(.*?)\] "(.*?)" (\d+) (\d+)'
    l = []
    for line in lines:
    path = re.match(regex, line).group(2)
    status_code = re.match(regex, line).group(3)
    size =re.match(regex, line).group(4)
    d = {'path': path, 'status_code': status_code, 'size': size}
    l.append(d)

    l_get_200 = [x for x in l if x['status_code'] == '200' and 'GET' in x['path']]

    data = {}
    for i in l_get_200:
    n = i.get('path').split()[1]
    if n not in data:
    data[n] = int(i.get('size'))
    else:
    data[n] += int(i.get('size'))

    for k,v in sorted(data.items(), key=lambda x: x[1]):
    print(k,v)