[Tutor] neeed help

Morne Morne" <fromclay@maxitec.co.za
Tue, 3 Sep 2002 13:34:07 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0083_01C2534E.9421E900
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi there ; here is what I have and then what I need the program to do .

import re
import string

secondsMatcher=3Dre.compile("Connect time: (\d+) secs")

def getStuff(file):
    closeline =3D 0
    errorcount =3D 0
    secondscount =3D 0
    connectcount =3D 0
    data_outcount =3D 0
    data_incount =3D 0
    ppplist =3D file.readlines()

    for line in ppplist:

      if string.find(line,"LayerUp") >=3D 0:
          print "found connect"
          connectline =3D string.split(line)
          connectcount =3D connectcount + 1
        =20
      elif string.find(line,"ERROR") >=3D 0:
          print "found error"
          errorcount =3D errorcount + 1

      elif string.find(line,"Connect time") >=3D 0:
          print "found close"
          connectSecs=3DsecondsMatcher.search(line).group(1)
          print "Connected for",connectSecs
          closeline =3D string.split(line)
          secondscount =3D secondscount + string.atoi(connectSecs)

def main():
    f=3Dopen("C:/my documents/ppp.log","r")
    getStuff(f)
    return None

if __name__=3D=3D"__main__":
    main()

WHEN I RUN THE PROGRAM:

Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>>=20
found close
Connected for 40
found connect
found connect
found close
Connected for 197
found close
Connected for 228
found close
Connected for 43
found connect
found connect

KNOW what IT SHOULD DO:

I want this program to read a .log file and give me the
following type of report:


PPP Log file summary for 5 Jul 2002
-----------------------------------
Jul  5 18:15:01 Connected to internet (IP 155.239.150.146)
Jul  5 18:18:08 Closed connection. ( Connect time: 197 secs: 5091 octets =
in,
1864 octets out )
-----------------------------------
Successful connections: 5
Failed connections: 2
Total time online: 456 seconds
Total data in: 66576 octets
Total Data out: 66349 octets

HOW WOULD I DO THAT ?

wpuld you please help me .










------=_NextPart_000_0083_01C2534E.9421E900
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi there ; here is what I have and then =
what I need=20
the program to do .</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>import re<BR>import string</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>secondsMatcher=3Dre.compile("Connect =
time: (\d+)=20
secs")</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def =
getStuff(file):<BR>&nbsp;&nbsp;&nbsp; closeline=20
=3D 0<BR>&nbsp;&nbsp;&nbsp; errorcount =3D 0<BR>&nbsp;&nbsp;&nbsp; =
secondscount =3D=20
0<BR>&nbsp;&nbsp;&nbsp; connectcount =3D 0<BR>&nbsp;&nbsp;&nbsp; =
data_outcount =3D=20
0<BR>&nbsp;&nbsp;&nbsp; data_incount =3D 0<BR>&nbsp;&nbsp;&nbsp; ppplist =
=3D=20
file.readlines()</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; for line in=20
ppplist:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if=20
string.find(line,"LayerUp") &gt;=3D=20
0:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
"found=20
connect"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
connectline =3D=20
string.split(line)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
connectcount =3D connectcount +=20
1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif string.find(line,"ERROR") =
&gt;=3D=20
0:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
"found=20
error"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
errorcount =3D=20
errorcount + 1</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif=20
string.find(line,"Connect time") &gt;=3D=20
0:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
"found=20
close"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
connectSecs=3DsecondsMatcher.search(line).group(1)<BR>&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
print "Connected=20
for",connectSecs<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
closeline =3D=20
string.split(line)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
secondscount =3D secondscount + string.atoi(connectSecs)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def main():<BR>&nbsp;&nbsp;&nbsp; =
f=3Dopen("C:/my=20
documents/ppp.log","r")<BR>&nbsp;&nbsp;&nbsp; =
getStuff(f)<BR>&nbsp;&nbsp;&nbsp;=20
return None</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>if =
__name__=3D=3D"__main__":<BR>&nbsp;&nbsp;&nbsp;=20
main()</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>WHEN I RUN THE PROGRAM:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Python 2.2.1 (#34, Apr&nbsp; 9 2002, =
19:34:33) [MSC=20
32 bit (Intel)] on win32<BR>Type "copyright", "credits" or "license" for =
more=20
information.<BR>IDLE 0.8 -- press F1 for help<BR>&gt;&gt;&gt; <BR>found=20
close<BR>Connected for 40<BR>found connect<BR>found connect<BR>found=20
close<BR>Connected for 197<BR>found close<BR>Connected for 228<BR>found=20
close<BR>Connected for 43<BR>found connect<BR>found =
connect<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>KNOW what IT SHOULD DO:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I want&nbsp;this program&nbsp;to read a =
.log file=20
and give me the<BR>following type of report:<BR><BR><BR>PPP Log file =
summary for=20
5 Jul 2002<BR>-----------------------------------<BR>Jul&nbsp; 5 =
18:15:01=20
Connected to internet (IP 155.239.150.146)<BR>Jul&nbsp; 5 18:18:08 =
Closed=20
connection. ( Connect time: 197 secs: 5091 octets in,<BR>1864 octets out =

)<BR>-----------------------------------<BR>Successful connections: =
5<BR>Failed=20
connections: 2<BR>Total time online: 456 seconds<BR>Total data in: 66576 =

octets<BR>Total Data out: 66349 octets<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>HOW WOULD I DO THAT ?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>wpuld you please help me=20
.<BR><BR><BR><BR><BR><BR><BR><BR><BR></DIV></FONT></BODY></HTML>

------=_NextPart_000_0083_01C2534E.9421E900--