← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #289066]: Variable values not carrying over to functions called from separate scripts

 

Question #289066 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/289066

    Status: Open => Answered

RaiMan proposed the following answer:
the usual way, when you have such a challenge (if I understand right),
is to apply parameters with the called function, that are filled with
the dynamic variables at the time they are called.

# main.sikuli (scheduler)
import adsFunctions
adsFunctions.ads1("content1", "content2", "content3")
adsFunctions.ads1("content1a", "content2a", "content3a")
adsFunctions.ads1("content1b", "content2b", "content3b")

# asFunctions.sikuli
def ads1(cont1, cont2, cont3):
    print "content1:", cont1
    print "content2:", cont2
    print "content3:", cont3

hence each job, that has to be done the same way, but with different
content, uses the same function, which is called with different
parameter values, that reflect the dynamic content.

This is one of the basic software design principles: DRY
... don't repeat yourself. 

the scheduler (main) itself then could be designed in a way, that it reads some input, where each line represents a job, to be done:
e.g. a CSV file with these columns FunctionToUse, Parameter1, Parameter2, Parameter3, Parameter4 

the file for the above example:
ads1,content1,content2,content3
ads1,content1a,content2a,content3a
ads1,content1a,content2a,content3a

# main
jobs = open("jobs.txt")
for line in jobs.readlines():
   parms = line.strip().split()
   if parms[0] == "ads1":
      adsFunctions.ads1(parms[1], parms[2], parms[3])

so to add a new job, that already has a function available , you simply
have to revise your file jobs.text and run main: no need to touch any
code, until the workflow changes.

You might even use an Excel sheet as input, that has a line for each
job, since SikuliX has the module xlrd bundled, that allows, to read
from an Excel sheet.

If you are thinking about assistants, then you should never design the workflow in a way, that they have to fiddle around with code. Instead they should use some tool to fill in the schedule information (what, when, how, ...) and the dynamic content.
The easiest tool is a text file, that is used by your main script, to execute what should be done based on the schedule content.
A more complex solution would be a database with one or  more input masks (a basic solution is even possible with Excel this way).
... and you might setup a WordPress website, that could be used this way (provided you use the appropriate plugins and setup the input masks).

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.