Home > Blockchain >  Taking user input and using it in another script
Taking user input and using it in another script

Time:12-17

I'm developing a python script to enter some corporative websites and extract the data that I need. So I have two kinds of scripts, the first one is to do the automation process and the second type is the "parent" script in which I use runpy to run the first kind of scripts and tkinter.simpledialog.askstring to ask the user their login and password. The problem that I'm facing is that I need to store the user's input (that I gather in my "parent" script) and use it in my automation script. This is my "parent" script:

import runpy
import pyautogui
import pyperclip
import tkinter as tk
import tkinter.simpledialog

pyautogui.PAUSE=1

tk.Tk().withdraw()
login=tkinter.simpledialog.askstring("Login","Enter login", show="")
password=tkinter.simpledialog.askstring("Password","Enter password", show="*")
time.sleep(2)
runpy.run_path('path to my automation script')

As you can see, it just stores the user's input and run another script. Below is the another type of script that is located on 'path to my automation script'.

from selenium import webdriver
import pyforest
import time
import pandas
import openpyxl
import pyautogui
from Parent_Script import login, password

driver=webdriver.Chrome(executable_path='path to chromedriver',options=options)
driver.get('corporative website')

login_website=driver.find_element_by_xpath('//*[@id="txtLogin"]')
login_website.send_keys(login)
password_website=driver.find_element_by_xpath('//*[@id="txtPassword"]')
password_website.send_keys(password)

I'm trying to import my parent script variables login and password but as a user I have to fill the tkinter dialogs two times (I think that the first fill occurs because I run the Parent script and the second one it's when the Parent script runs the Automation script and thus it re-run the Parent script to do the variable import). Is there a better (or right) way to make it work effectively ?

CodePudding user response:

While I was waiting for an answer I've found a solution. Well, kind of.

I removed all tkinter stuff from my "Parent" script and created a module named "Login_Password". The whole script of this module is:

import tkinter as tk
import tkinter.simpledialog

tk.Tk().withdraw()
login=tkinter.simpledialog.askstring("Login","Enter login", show="")
password=tkinter.simpledialog.askstring("Password","Enter password", show="*")

Then I moved my Login_Password module to the path of site-packages from Python to be able to import it as a module in my automation script and it's working fine now.

  • Related