I have something working with xmlrpc
In web2py i have this service!
@service.xmlrpc
def getFile(file,name):
db(
db.files.id>0).delete()
lixo = glob.glob(os.path.join(request.folder,'uploads','*.txt'))
for f in lixo: # i delete all files in the folder then i receive the new one
os.remove(f)
filedata=cStringIO.StringIO(file.data)
file=db.files.file.store(filedata,name)
db.files.insert(file=file)
return "Import - OK"
Then i have a script outside web2py with this code.
This code gets a csv file from an email i receive everyday in my inbox and sends it to my web2py server.
Just notice the bold lines. The rest is Lotus Notes specific...
import xmlrpclib
import win32com.client
import sys
import time
filebin=None
session = win32com.client.Dispatch('Lotus.NotesSession')
session.Initialize('mypassword')
db = session.GetDatabase('SIGMA','mail/mymailbox.nsf')
view = db.GetView('CYGSA')
doc = view.GetFirstDocument()
try:
body=doc.GetFirstItem('Body')
file=doc.GetAttachment("LCOBROS.csv")
file.ExtractFile("c:\\LCOBROS.txt")
server = xmlrpclib.ServerProxy('http://10.0.0.100/ERP/default/call/xmlrpc') filepath='c:\\'
filename='LCOBROS.txt'
filebin = xmlrpclib.Binary(open(filepath+filename).read()) print server.getFile(filebin,filename)
doc.remove(False) # i delete the email with that attachment
except:
pass