formatting file

2005-04-06 Thread SPJ
Hi,

I am new to python hence posing this question.
I have a file with the following format:

test11.1-1   installed
test11.1-1   update
test22.1-1   installed
test22.1-2   update

I want the file to be formatted in the following way:

test11.1-1   1.1-2
test22.1-1   2.1-2

How can I achieve this? I am stuck here.

Thanks in advance.
spj



__ 
Yahoo! Messenger 
Show us what our next emoticon should look like. Join the fun. 
http://www.advision.webevents.yahoo.com/emoticontest
-- 
http://mail.python.org/mailman/listinfo/python-list


Writing to multiple excel worksheets

2007-09-17 Thread SPJ
Hi,

I have a list which I need to write to excel worksheet. The list is like:
data = 
['IP1','21','ftp','\n','IP1','22','ssh','\n','IP2','22','ssh','\n','IP2','23','telnet','\n']
Now the task is to create a workbook with tabbed sheet for each of the 
service's in the list i.e. tabs for ftp, ssh, telnet etc. The data needs to be 
written in the corresponding sheets. 

What is the best way to achieve this?
I couldn't find much help on the internet nor in the earlier threads. Please 
help.

Thanks,
SPJ

   
-
Yahoo! oneSearch: Finally,  mobile search that gives answers, not web links. -- 
http://mail.python.org/mailman/listinfo/python-list

Reading new mail from outlook

2008-03-24 Thread SPJ
Hi,I am trying to create new tickets in the ticketing system using python. When I receive new email from a particular address, I have to trigger the python script and parse the mail  in required format. The  main hurdle here is,  how to invoke the script on arrival of new mail? I checked the outlook settings and found that it supports only microsoft _vbscript_ and Jscript. Is there any other way? I mean, if I make a daemon, how will it be notified of new mail? Is there any python module that does this? I am not sure if this is the right place to ask this, since it is also a microsoft related question. But any help is appreciated.Thanks,SPJ
  Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reading new mail from outlook using Python

2008-03-24 Thread SPJ
Hi,I am trying to create new tickets in the ticketing system using python. When I receive new email from a particular address, I have to trigger the python script and parse the mail  in required format. The  main hurdle here is,  how to invoke the script on arrival of new mail? I checked the outlook settings and found that it supports only microsoft _vbscript_ and Jscript. Is there any other way? I mean, if I make a daemon, how will it be notified of new mail? Is there any python module that does this? I am not sure if this is the right place to ask this, since it is also a microsoft related question. But any help is appreciated.Thanks,SPJ
  Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.
-- 
http://mail.python.org/mailman/listinfo/python-list

FW:Reading new mail from outlook express using Python

2008-03-24 Thread SPJ
My previous post was not clear, hence resending this.

-
Hi,

I am trying to create new tickets in the ticketing system using python. When I 
receive new email from a particular address, I have to trigger the python 
script and parse the mail  in required format. 

The  main hurdle here is,  how to invoke the script on arrival of new mail? I 
checked the outlook settings and found that it supports only microsoft VB 
script and Jscript. Is there any other way? I mean, if I make a daemon, how 
will it be notified of new mail? Is there any python module that does this? 

I am not sure if this is the right place to ask this, since it is also a 
microsoft related question. But any help is appreciated.

Thanks,
SPJ



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading new mail from outlook using Python

2008-03-25 Thread SPJ
Thanks...

I could access the folders in outlook express using the COM interface. Now I am 
stuck with how to read to a file only new mails. 

Anyone knows how to achieve this?

Thanks
SPJ


--- On Tue, 3/25/08, Pete Stapley <[EMAIL PROTECTED]> wrote:

> From: Pete Stapley <[EMAIL PROTECTED]>
> Subject: Re: Reading new mail from outlook using Python
> To: [EMAIL PROTECTED]
> Cc: [email protected]
> Date: Tuesday, March 25, 2008, 2:58 AM
> Well on a FreeBSD/Unix system you can use the .forward to
> pipe the 
> incoming mail for a user to a program. Below is the
> contents of my 
> .forward that invokes procmail.
> 
> "|/usr/local/bin/procmail -m
> /path/to/conf/.procmailrc"
> 
> So I imagine you could do something like this in a
> .forward.
> 
> "|/path/myprogram.py"
> 
> SPJ wrote:
> > Hi,
> >
> > I am trying to create new tickets in the ticketing
> system using 
> > python. When I receive new email from a particular
> address, I have to 
> > trigger the python script and parse the mail  in
> required format.
> >
> > The  main hurdle here is,  how to invoke the script on
> arrival of new 
> > mail? I checked the outlook settings and found that it
> supports only 
> > microsoft VB script and Jscript. Is there any other
> way? I mean, if I 
> > make a daemon, how will it be notified of new mail? Is
> there any 
> > python module that does this?
> >
> > I am not sure if this is the right place to ask this,
> since it is also 
> > a microsoft related question. But any help is
> appreciated.
> >
> > Thanks,
> > SPJ
> >
> >
> >
> 
> > Be a better friend, newshound, and know-it-all with
> Yahoo! Mobile. Try 
> > it now. 
> >
> <http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20>


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Question regd downloading multipart mail using POP3

2008-03-28 Thread SPJ
I am facing a strange problem when I am trying to retrieve multipart mail from 
POP server with attachments.
The task is to write a script which will retrieve mail with specific 'from' 
field. Get the subject, body and attachments if any and reuse this info to send 
mail with different format to ticketing system.

The global variable values I am expecting is:
msgList = [[msg1_subject,msg1_body,0],[msg2_subject,msg2_body,1]] and so on
attachmentList=[['none'],['attachname.txt','filename.pl']]
where none is no attachments.

But the result I am getting is:
msgList = [[msg1_subject,msg1_body,0],[msg2_subject,msg2_body,1]] and so on
attachmentList=[[none],['none', 'attachname.txt', 'filename.pl']]

An extra 'none' in the attachment list except for plain/text mails without 
attachments.
I have tried a lot to figure out how to eliminate this but with no luck do far 
:(
I know that some part is getting excluded from the condition, but I am unable 
to figure out what is causing this. 

Following is the function I wrote:
I am not an expert programmer hence my code is not clean, so pl. bear with me. 

Thanks,
SPJ

--
import poplib, email, re, sys, os

msgList = [] # Global list that contains messages
PATH = Path to save file on disk
# path were attachements will be stored
attachmentName = [] # Name of attachements 

def popconnect():
# connect the pop server and send username and password
pconnect = poplib.POP3(server)
pconnect.user(user)
pconnect.pass_(passwd)
   
   # Give connection status, msg list and total msg size
status, msg_list, octets = pconnect.list()
if len(msg_list) == 0:
print "No messages in Mailbox"
pass
# regex for searching mails from [EMAIL PROTECTED]
soc = re.compile("[EMAIL PROTECTED]")

   # iterate over the number of new messages from counterpane and qppend the 
required fields
# to a list. 
for msg_number in [msg.split(' ')[0] for msg in msg_list]:
status, lines, octets = pconnect.retr(msg_number)
msg1 = email.message_from_string('\n'.join(lines))
tmpList = []
attachList = []
attachnumber = 0

check1 = msg1.get('From')
check2 = msg1.get('Subject')

if soc.match(check1):
subject = msg1.get('Subject') # Subject for only mails only after 
condition is true.

if msg1.is_multipart():
  
for part in msg1.walk():
# multipart/* are just containers
mptype = part.get_content_maintype()
body = part.get_payload(decode=True)

if mptype == "multipart": continue
filename = part.get_filename()

if filename: # Attached object with filename
print 'in file ' +part.get_content_type()
attachnumber += 1

tmpList[2] = attachnumber # number of attachments in 
message
attachList.append(PATH+filename) # path to attachment

# Copy the attachment to disk
f = open(PATH + filename,"wb")
f.write(part.get_payload(decode = True))
f.close()

else:
print part.get_content_type()

if part.get_content_type() != ("text/html" or 
"text/plain" or "multipart/alternative" or "multipart/mixed"):
tmpList.append(subject) # Subject from message
tmpList.append(body)  # Body from message
tmpList.append(0)# If no attachments
attachList.append('none')

else: # Not multipart, only body portion exists

print "Not Multipart\n"
body=msg1.get_payload(decode=True)
tmpList.append(subject) # Subject from message
tmpList.append(body)
tmpList.append(0)
attachList.append('none')

if len(tmpList) > 0:
msgList.append(tmpList)

if len(attachList) > 0:
attachmentName.append(attachList)

print msgList, attachmentName

pconnect.quit()

def main():
popconnect()

if __name__== '__main__':

main()



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Running commands on cisco routers using python

2008-05-19 Thread SPJ
Is it possible to run specific commands on cisco router using Python? 
I have to run command "show access-list" on few hundred cisco routers and get 
the dump into a file. Please let me know if it is feasible and the best way to 
achieve this.

Thanks,
SPJ 


  
--
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2008-04-18 Thread SPJ
I am writing a script which need's to convert an excel file to csv (text) 
format. For that I am using the following code:

excel = win32com.client.Dispatch("Excel.Application","Quit")
workbook = excel.Workbooks.Open(xlsfile)
workbook.SaveAs(csvfile, FileFormat=24) # 24 represents xlCSVMSDOS
workbook.Close(False)
excel.Quit()

I did not have any problem running this script on a windows xp machine with 
python 2.5.2 and windows extensions. But I get the following error when I run 
the same script on a windows 2003 server with the same python and windows 
extension installation:

excel = win32com.client.Dispatch("Excel.Application","Quit")
  File "D:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in 
Dispatch
dispatch, userName = 
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "D:\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in 
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "D:\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in 
_GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, 
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

I verified that installation is same. Any idea's as to what might be the 
problem? One thing I have noticed though is I can't see Microsoft office 11.0 
object library when I do combrowse on windows 2003 server. I also to tried to 
reinstall python and windows extension. But still no luck.

I would appreciate if anyone can guide me as to why this is happening and how 
to resolve this. 

Thanks,
SPJ


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Error with win32com client on windows 2003 server

2008-04-18 Thread SPJ
Sorry, forgot to mention Subject in my earlier post, hence reposting.

I am writing a script which need's to convert an excel file to csv (text) 
format. For that I am using the following code:

excel = win32com.client.Dispatch("Excel.Application","Quit")
workbook = excel.Workbooks.Open(xlsfile)
workbook.SaveAs(csvfile, FileFormat=24) # 24 represents xlCSVMSDOS
workbook.Close(False)
excel.Quit()

I did not have any problem running this script on a windows xp machine with 
python 2.5.2 and windows extensions. But I get the following error when I run 
the same script on a windows 2003 server with the same python and windows 
extension installation:

excel = win32com.client.Dispatch("Excel.Application","Quit")
  File "D:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in 
Dispatch
dispatch, userName = 
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "D:\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in 
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "D:\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in 
_GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, 
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

I verified that installation is same. Any idea's as to what might be the 
problem? One thing I have noticed though is I can't see Microsoft office 11.0 
object library when I do combrowse on windows 2003 server. I also to tried to 
reinstall python and windows extension. But still no luck.

I would appreciate if anyone can guide me as to why this is happening and how 
to resolve this. 

Thanks,
SPJ


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:Error with win32com client on windows 2003 server

2008-04-18 Thread SPJ
I got the reason for why this is happening. MS office is not installed on that 
server.

Thanks anyways..
SPJ


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-- 
http://mail.python.org/mailman/listinfo/python-list