← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #692219]: python sikuli issue

 

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

RaiMan proposed the following answer:
Generally: Python variables should start with a lowercase letter and
consist only of letters numbers and underscore.

First trial with Region().text() is not recommended, because the OCR
feature is not 100% reliable.

Second case:
timeNow = run("date +%H%M")
this returns a string containing 2 lines (1st return value, 2nd the result of date)
in this case you get 0\n0951

to get something useable:
timeNow = -1
result = run("date +%H%M").split()
if result[0] == "0":
    timeNow = int(result[1]) # timeNow is 951
    print "timeNow =", timeNow
    if timeNow > 1245:
        print "it is 12:46 or later"
    else:
        print "it is earlier than 12:46"

... or as float as you tried:
timeNow = -1
result = run("date +%H.%M").split() # the dot has to be in the format spec
if result[0] == "0":
    timeNow = float(result[1]) # timeNow is 9.51
    print "timeNow =", timeNow
    if timeNow > 12.45:
        print "it is 12:46 or later"
    else:
        print "it is earlier than 12:46"
    
But why inventing the wheel again - you have Python:
https://docs.python.org/2/library/time.html#time.strftime

timeNow = float(time.strftime("%H.%M"))
print "timeNow =", timeNow
if timeNow > 12.45:
    print "it is 12:46 or later"
else:
    print "it is earlier than 12:46"

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