Copy Multiple Login Details From A text file and Login?

Asked by Joe Harris

Hello. So I want Sikuli Login into email account by the login details present in a notepad file. Actually, Multiple Login details of the same account. I can manage the login and logout part. But how to make it select email, and put it in the email region. Get Password, Put in the password field. Then I can put wait("logged in image").Then do a specified job and logout. Then move on the next email account?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- select email:
look at the docs: http://sikuli.org/docx/globals.html#controlling-applications-and-their-windows

--- read from notepad file

theFile = file("absolute-path-to-the-notepad-file")
for line in theFile:
    print line # prints the lines to the message area
theFile.close()

change "print line" to your needed code.

Revision history for this message
Joe Harris (b5360657) said :
#2

Thanks for the feedback.
1) How do you manage to answer so many peoples questions? :D
2) The Code didn't worked,

run("notepad.exe")
theFile = file("C:\1.log.txt")
for line in theFile:
    App.focus("firefox.exe")
    paste line( )
     # prints the lines to the message area
theFile.close()

I'm getting a error :(

Revision history for this message
RaiMan (raimund-hocke) said :
#3

1) one of my hobbies - currently I have the time

2) before pasting around and running apps, you should assure, that the basics are working

-- step 1: try this in a new script tab with an existing file (C:\1.log.txt here), that contains some lines:

theFile = file(r"C:\1.log.txt")
for line in theFile:
    print line # prints the lines to the message area
theFile.close()

this should print the lines from your file in the IDE's message area

Take care: \ in strings has to be doubled/escaped as \\ or you use raw string r"" (like i did here)

-- step 2:

your snippet:

# run("notepad.exe") # delete this, not needed
theFile = file(r"C:\1.log.txt")

App.focus("firefox.exe") # does not make sense inside the loop

for line in theFile:
# paste line( ) # this is not Python
    paste(line) # this will paste at current cursor position in FF
theFile.close()

-- general comment:
If you have some errors, it would be helpful, to paste them here or at least name them, so I do not have to guess, what errors you might have had.

Revision history for this message
Joe Harris (b5360657) said :
#4

1)Umm, It's weird, might be a bug.

When I use,
theFile = file(r"C:\1.log.txt")
for line in theFile:
    print line # prints the lines to the message area
theFile.close()

It doesn't works.
But when I remove the .txt from the path i.e C:\1.log. it works.

2) I want to sikuli to copy logins from a notepad,
 I want to use the first line, then Perform function. then use second line and perform function.
like this
Suppose $Email is Email addresses and $Pass is passwords
          a) How should I arrange so Sikuli/python can extract it?
          b) Is it possible?(If no, you may not answer the questions it'll be a time waste)
I had thought of arrange like
$Email:$Pass
$Email2:$Pass2

or
$Email1
$Pass1
$Email2
$Pass2
Or Email And Password have two different files? I don't know which might be possible, just told what i had in mind

Revision history for this message
Joe Harris (b5360657) said :
#5

I'm sorry forgot the errors again.

---1) When I use,
theFile = file(r"C:\1.log.txt")
for line in theFile:
    print line # prints the lines to the message area
theFile.close()

Error

[error] Stopped [error] An error occurs at line 1 [error] Error message: Traceback (most recent call last): File "C:\DOCUME~1\Vaibhav\LOCALS~1\Temp\sikuli-tmp676213472306671517.py", line 1, in theFile = file(r"C:\1.log.txt") IOError: (2, 'ENOENT', 'C:\\1.log.txt')

Revision history for this message
Joe Harris (b5360657) said :
#6

Is this is a bug?

Revision history for this message
RaiMan (raimund-hocke) said :
#7

Sorry, somehow lost this one.

I will check and come back soon.

Revision history for this message
RaiMan (raimund-hocke) said :
#8

No, this is not a bug.

This is a somewhat cryptic error message meaning: file not found.

if you open a file for reading by
theFile = file(r"C:\1.log.txt")

it MUST exist.

So if
file(r"C:\1.log.")
works, there MUST be a file C:\1.log.

So in your case to test it, fill some lines into it with notepad before.

Revision history for this message
Joe Harris (b5360657) said :
#9

Still Figuring out how Do I copy logins from notepad?

Revision history for this message
Joe Harris (b5360657) said :
#10

Still Figuring out how Do I copy logins from notepad?

Revision history for this message
RaiMan (raimund-hocke) said :
#11

the suggestion is, to not copy from a notepad window, but from a file, that was setup and saved with notepad.

So what about that?

Revision history for this message
Joe Harris (b5360657) said :
#12

Okay. But How Do I Get strings from the file?

Which are in.
email:pass
email:pass
Style.?

Revision history for this message
Best RaiMan (raimund-hocke) said :
#13

theFile = file(r"path-to-the-file-that-contains-the-email:pass-lines.txt")
for line in theFile:
    line = line.strip()
    if len(line) == 0: continue
    print line
    (email, password) = line.split(":")
    email = email.strip()
    password = password.strip()
    print "email=", email
    print "password=", password
theFile.close()

this works, as long each line contains only one colon and this is between email and password.
x.strip() gets rid of surrounding whitespace.

Revision history for this message
Joe Harris (b5360657) said :
#14

Thanks RaiMan, that solved my question.

Revision history for this message
Joe Harris (b5360657) said :
#15

Thanks alot. Sorry for troubling alot. got it finally :)

Revision history for this message
RaiMan (raimund-hocke) said :
#16

No sorry, no troubling ;-)

In Germany we have a saying:
There are no stupid questions, only stupid answers.

So I am happy, that my answers where of some help.

All the best.