-
Notifications
You must be signed in to change notification settings - Fork 2
CommunicationScriptsType
In this case, the channel must be configured with Type: communicationscript.
In the communicationscript some functions will be called:
- connect (required)
- main (optional, 'main' should handle files one by one)
- disconnect (optional)
Different ways of working:
-
for incoming files (bots receives the files):
- connect puts all files in a directory, there is no 'main' function. bots can remove the files (if you use the 'remove' switch of the channel). See example 1.
- connect only builds the connection, 'main' is a generator that passes the messages one by one (using 'yield'). bots can remove the files (if you use the 'remove' switch of the channel). See example 2.
-
for outgoing files (bots sends the files):
- no 'main' function: the processing of all the files can be done in 'disconnect'. bots can remove the files (if you use the 'remove' switch of the channel). See example 3.
- if there is a 'main' function: the 'main' function is called by bots after writing each file. bots can remove the files (if you use the 'remove' switch of the channel). See example 4.
Calls an external program.
Think eg of a specific communication module for a VAN.
All files are received at once to a folder, then processed like a
normal file channel.
import subprocess
def connect(channeldict,*args,**kwargs):
subprocess.call(['C:/Program files/my VAN/comms-module.exe','-receive'])
TODO: make a valid example using yield.
main is a generator.
import subprocess
def connect(channeldict,*args,**kwargs):
''' function does nothing but it is required.'''
pass
def main(channeldict,*args,**kwargs):
yield ?
Calls an external program.
Think eg of a specific communication module for a VAN.
In this example the 'disconnect' script is called after all files are
written to directory;
in disconnect all files are passed to external communication-module.
import subprocess
import os
def connect(channeldict,*args,**kwargs):
''' function does nothing but it is required.'''
pass
def disconnect(channeldict,*args,**kwargs):
subprocess.call(['C:/Program files/my VAN/comms-module.exe','-send',os.path.join(channeldict['path'],'*.xml'])
Calls an external program.
Think eg of a specific communication module for a VAN.
In this example the 'main' script is called for each outgoing file.
import subprocess
def connect(channeldict,*args,**kwargs):
''' function does nothing but it is required.'''
pass
def main(channeldict,filename,ta,*args,**kwargs):
subprocess.call(['C:/Program files/my VAN/comms-module.exe','-send',filename])
Send data (eg. ZPL code to print fancy labels) directly to a Windows
configured printer.
The printer can be defined in Windows either as "Generic/Text Only" or
with the proper driver, because this script just sends raw data, bypassing the
driver.
Dependencies: Requires pywin32
Reference: http://timgolden.me.uk/pywin32-docs/win32print.html
import os
import win32print
import bots.transform as transform
def connect(channeldict,*args,**kwargs):
''' function does nothing but it is required.'''
pass
def main(channeldict,filename,ta,*args,**kwargs):
# set printer values required
ta.synall()
printer = transform.partnerlookup(ta.topartner,'attr1')
jobname = ta.botskey
# read the output file
with open(filename,'r') as content_file:
content = content_file.read()
# send data to the printer
hPrinter = win32print.OpenPrinter(printer)
hJob = win32print.StartDocPrinter(hPrinter,1,(jobname,None,'RAW'))
win32print.WritePrinter(hPrinter,content)
win32print.EndDocPrinter(hPrinter)
win32print.ClosePrinter(hPrinter)
[Home]
- Get started with bots
- Guide for bots-monitor
- Configuration
- How to debug
- Plugins
- Deployment and usage
- Advanced Deployment
- Troubleshooting FAQ
- Overview
- Changes and migrate
- Tutorials
- New to python?
- External reference links
- Useful Tools