示例#1
0
## @author: vladimir kulyukin

import sys

## change this path to where WebLogEntry.py
load_path = 'C:\\users\\vladimir\\programming\\nasa_wlog\\py_nasa_log\\'

if __name__ == '__main__':
    if not load_path in sys.path:
        sys.path.append(load_path)

from WebLogEntry import WebLogEntry

txt3 = 'pipe2.nyc.pipeline.com - - [01/Jul/1995:22:41:11 -0400] "GET /shuttle/missions/sts-71/sts-71-patch-small.gif" 200 12054'
wle3 = WebLogEntry();

if wle3.toWebLogEntry(txt3):
    print 'IP:      ' + wle3.getIP() + "\n",
    print 'TS:      ' + wle3.getTimestamp().toString() + "\n",
    print 'METHOD:  ' + wle3.getMethod() + "\n",
    print 'URL:     ' + wle3.getURL() + "\n",
    print 'PROTOCOL ' + wle3.getProtocol() + "\n",
    print 'STATUS   ' + str(wle3.getStatusCode()) + "\n",
    print 'TRBYTES  ' + str(wle3.getTransBytes()) + "\n",

    print "\n\nGENERATED HTML\n"
    print wle3.toHtmlUL()
else:
    print 'no WebLogEntry object created' + "\n",
示例#2
0
#!/usr/bin/python

import sys

## change this path to where WebLogEntry.py
load_path = 'C:\\users\\vladimir\\programming\\nasa_wlog\\py_nasa_log\\'

if __name__ == '__main__':
    if not load_path in sys.path:
        sys.path.append(load_path)

from WebLogEntry import WebLogEntry

txt1 = '199.72.81.55 - - [01/Jul/1995:00:00:01 -0400] "GET /history/apollo/ HTTP/1.0" 200 6245'
wle1 = WebLogEntry()
if wle1.toWebLogEntry(txt1):
    print 'IP:      ' + wle1.getIP() + "\n",
    print 'TS:      ' + wle1.getTimestamp().toString() + "\n",
    print 'METHOD:  ' + wle1.getMethod() + "\n",
    print 'URL:     ' + wle1.getURL() + "\n",
    print 'PROTOCOL ' + wle1.getProtocol() + "\n",
    print 'STATUS   ' + str(wle1.getStatusCode()) + "\n",
    print 'TRBYTES  ' + str(wle1.getTransBytes()) + "\n",

    print "\n\nGENERATED HTML\n"
    print wle1.toHtmlUL()
else:
    print 'no WebLogEntry object created' + "\n",
示例#3
0
        sys.path.append(load_path)

from WebLogEntry import WebLogEntry

## 1. get the command line arguments
lower = int(sys.argv[1]) ## lower bound
upper = int(sys.argv[2]) ## upper bound
top_n = int(sys.argv[3]) ## top_n
html_fp = sys.argv[4]    ## output html file path

## 2. Read in all text entries, convert them into WebLogEntry objects,
##    and place them into web_log_entries.
web_log_entries = []
for line in [line for line in sys.stdin.readlines()
             if re.match(r'\S+', line)]:
    wle = WebLogEntry()
    if wle.toWebLogEntry(line):
        web_log_entries.append(wle)
    else:
        print 'FAILURE: ' + line

## this is a debug print to show how many objects we have constructed        
print len(web_log_entries)

## 3. grep all entries whose transferred bytes are in [lower, upper]
web_log_entries = filter(lambda x: x.getTransBytes() >= lower and x.getTransBytes() <= upper, web_log_entries)
## 4. sort all entries in the range from highest to lowest
web_log_entries.sort(key=lambda x: x.getTransBytes(), reverse=True)


with open(html_fp, 'w') as outstream:
示例#4
0
    if not load_path in sys.path:
        sys.path.append(load_path)

from WebLogEntry import WebLogEntry

## 1. get the command line arguments
lower = int(sys.argv[1])  ## lower bound
upper = int(sys.argv[2])  ## upper bound
top_n = int(sys.argv[3])  ## top_n
html_fp = sys.argv[4]  ## output html file path

## 2. Read in all text entries, convert them into WebLogEntry objects,
##    and place them into web_log_entries.
web_log_entries = []
for line in [line for line in sys.stdin.readlines() if re.match(r'\S+', line)]:
    wle = WebLogEntry()
    if wle.toWebLogEntry(line):
        web_log_entries.append(wle)
    else:
        print 'FAILURE: ' + line

## this is a debug print to show how many objects we have constructed
print len(web_log_entries)

## 3. grep all entries whose transferred bytes are in [lower, upper]
web_log_entries = filter(
    lambda x: x.getTransBytes() >= lower and x.getTransBytes() <= upper,
    web_log_entries)
## 4. sort all entries in the range from highest to lowest
web_log_entries.sort(key=lambda x: x.getTransBytes(), reverse=True)