Last active
January 29, 2018 06:30
-
-
Save MishraKhushbu/8b9377cf97a569580aac6002fa4b37bc to your computer and use it in GitHub Desktop.
Karthik task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
#Opening the file | |
f0 = open("out.txt","rw+") #File containing the original testing report. | |
f1 = open("new.txt","rw+") #File containg the report in string format | |
f2 = open("new3.txt","rw+")#File containing the required fields in string format | |
f3 = open("book2.csv","w+")#csv file with the value for keys | |
#function to remove whitespaces from file out.txt and writing it in new.txt | |
if you want line 7 | |
line = open("file.txt", "r").readlines()[7] | |
for line in f0: | |
line = line.replace(" "," ").strip() | |
line = line.replace(" "," ") | |
line = line.replace(" "," ") | |
line = line.replace(" "," ") | |
if( line != ""): | |
f1.write(line + ',') | |
else: | |
print line | |
#Function for parsing the file f1 to get only the required field in string format | |
for line in f1: | |
ab = 'Server Hostname' | |
cd = 'Connection Times' | |
p = line.find(ab) | |
p1 = line.find(cd) | |
i = p | |
for h in range (0,1): | |
f1.seek(p) | |
length = ((line.find(cd)-1)-(line.find(ab))) | |
length = (length-33) | |
a = f1.read(length) | |
v = a.replace('(mean, across all concurrent requests)','') | |
v = v.replace('(mean)','') | |
#print('"'+v+'"') | |
break | |
f2.write('"'+v+'"') # Writing the required field in string format in file f2 | |
#Storing the contents of file f2 in variable | |
with open("new2.txt","rw+") as f2: | |
p =f2.read() | |
#print ('getting the contents of f2 file:',p) | |
#making Dictionary out of string | |
c = (dict(item.split(":") for item in p.split(","))) | |
#print ('items of dictionary c:',c) | |
#Writing the key values into csv file | |
f3.write(c['Server Hostname']+',') | |
f3.write(c['Server Port']+',') | |
f3.write(c['Document Path']+',') | |
f3.write(c['Document Length']+',') | |
f3.write(c['Concurrency Level']+',') | |
f3.write(c['Time taken for tests']+',') | |
f3.write(c['Complete requests']+',') | |
f3.write(c['Failed requests']+',') | |
f3.write(c['Non-2xx responses']+',') | |
f3.write(c['Total transferred']+',') | |
f3.write(c['Total body sent']+',') | |
f3.write(c['HTML transferred']+',') | |
f3.write(c['Requests per second']+',') | |
f3.write(c['Time per request']+',') | |
f3.write(c['Time per request']+',') | |
f3.write(c['Transfer rate']+',') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment