Python – Call variable from function using args with threading

  multithreading, python, tkinter

Using selenium to calculate 2 integers together,
But the problem that is too slow Processing one webdriver at a time.

I was wondering how can I run those two function together..

I’ve got few files that I’m running the script from:

extra.py

    from selenium import webdriver
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from config import *


def horizon_loginbhb():
    browser1 = webdriver.Chrome()
    browser1.get('https://forums.gamers-israel.co.il/')
    WebDriverWait(browser1, 10).until(ec.title_contains("בית"))
    browser1.find_element_by_id('lnkLoginSignupMenu').click()
    browser1.find_element_by_name('username').send_keys(config['Login']['Username'])
    browser1.find_element_by_name('password').send_keys(config['Login']['Password'])
    browser1.find_element_by_xpath('//*[@id="vb-page-body"]/nav/div/ul/li/div/ul/li[1]/div/form/div[3]/button').click()
    first = browser1.find_element_by_xpath('//*[@id="forum21"]/td[2]').text
    var1 = int(first.splitlines()[0])

    browser1.close()

    return var1


def horizon_loginsrq():
    browser2 = webdriver.Chrome()
    browser2.get('https://forums.gamers-israel.co.il/')
    WebDriverWait(browser2, 10).until(ec.title_contains("בית"))
    browser2.find_element_by_id('lnkLoginSignupMenu').click()
    browser2.find_element_by_name('username').send_keys(config['Login']['Username'])
    browser2.find_element_by_name('password').send_keys(config['Login']['Password'])
    browser2.find_element_by_xpath('//*[@id="vb-page-body"]/nav/div/ul/li/div/ul/li[1]/div/form/div[3]/button').click()
    second = browser2.find_element_by_xpath('//*[@id="forum23"]/td[2]').text
    var2 = int(second.splitlines()[0])
    browser2.close()

    return var2

gui.py (this is the main file)

    from tkinter import *
from extra import *
from tkinter import ttk

import threading

lock = threading.Lock()
window = Tk()

window.title("Mosh Counter")

tab_control = ttk.Notebook(window)
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)
tab_control.add(tab1, text='First')
tab_control.add(tab2, text='Second')
lbl1 = Label(tab1, text='Current sessions')
lbl1.grid(column=0, row=0)
lbl2 = Label(tab2, text='label2')
lbl2.grid(column=0, row=0)
tab_control.pack(expand=1, fill='both')

def messagecount():
    var1, var2 = horizon_loginbhb(), horizon_loginsrq()
    print(var2.get())
    print(int(var1) + int(var2))
    msg = (int(var1) + int(var2))
    lbl1_2 = Label(tab1, text=msg)
    lbl1_2.grid(column=0, row=2)
    window.after(5000, messagecount)


# run first time
messagecount()

window.mainloop()

I’m using another config files for the users and password (You don’t really need them).
Any idea to make it faster, also if you have some advices to make the code better I’ll be glad to hear?

Source: Python Questions

LEAVE A COMMENT