Hylafax Mailing List Archives
|
[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
Re: [hylafax-users] Python Hylafax?
Boingo wrote:
Hi there,
I am trying to send a fax from python, just using modules (i.e. no
GUI), from a separate machine (i.e. not the server).
<-cut->
Like you can read on the pyla and other sources (included the
hylafax-hfaxd C ), hylafax (hfaxd) is a ftp "server", so for send a file
you have only to send the right commands to the server with any
language. With python you can use the ftplib library for do the work.
Any help anyone can provide, would be greatly appreciated. Even a
basic example would be a huge help! I have been trying to find the
answer to this all over the place, and google comes up blank (at
least with my search terms).
< - code from hylaproto.py ( hylapex.sf.net ) ->
class SendFile:
i= 0
steps = 0
filesize = 0
def __init__(self,filename):
self.filesize = os.stat(filename)[6]
self.ft = open(filename,'rb')
def read(self,readbuf):
buf = self.ft.read(readbuf)
if buf: return buf
else: self.ft.close()
ftp = ftplib.FTP()
ftp.set_pasv(passive)
ftp.sendcmd('USER '+username)
files = ("file1.pdf", "file2.pdf")
parameter = {}
parameter['FROMUSER'] = username
parameter['NOTIFYADDR'] = email
parameter['LASTTIME'] = '010000'
parameter['MAXDIALS'] = maxdials
parameter['SCHEDPRI'] = 127
parameter['NOTIFY'] = '"done+requeue"'
parameter['SENDTIME'] = 'Now'
parameter['DIALSTRING'] = faxNumber
file2snd = list()
for file in files:
f = open(file)
header = f.read(4); f.close()
if header == "%!PS": ftp.sendcmd('FORM PS')
elif header == "%PDF": ftp.sendcmd('FORM PS')
else: ftp.sendcmd('FORM TIFF')
try:
fd = SendFile(file)
except Exception, msg:
msg = get_exdesc(msg)
file2snd.append(self.ftp.storbinary('STOT',fd,10240))
parameter['vres'] = '196'
parameter['pagewidth'] = '209'
parameter['pagelength'] = '296'
parameter['pagechop'] = 'default'
parameter['chopthreshold'] = '3'
try:
ftp.sendcmd('JNEW')
for jparm in parameter.keys():
ftp.sendcmd('JPARM %s %s' % (jparm,parameter[jparm]))
for files in file2snd:
filename = string.split(files)[-1][:-2]
ftp.sendcmd('JPARM %s %s' % ('document', filename))
ftp.sendcmd('JSUBM')
ftp.quit()
except Exception, msg:
print 'Error on send fax', msg
Thank you again in advance for any help you can give me.
I hope that this example that become from my fax client - hylapex - can
do what you want...
Michele Petrazzo
____________________ HylaFAX(tm) Users Mailing List _______________________
To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null
*To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*