from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.core.window import Window
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
import selenium.webdriver.support.ui as ui
from selenium.webdriver.support.ui import WebDriverWait
import selenium.webdriver.support.expected_conditions as EC
import os
import getpass
import time
import pymsgbox
Window.size = (300, 120)
#PcName = getpass.getuser()
class Kite(GridLayout):
def __init__(self, **kwargs):
super(Kite, self).__init__(**kwargs)
self.cols=3
self.btn_buy = Button(text="Buy")
self.btn_buy.bind(on_press=self.buy_button_click)
self.add_widget(self.btn_buy)
self.btn_sell = Button(text="Sell")
self.btn_sell.bind(on_press=self.buy_button_click)
self.add_widget(self.btn_sell)
self.txtOption = TextInput(id="txtoption",font_size=16,disabled=True)
self.add_widget(self.txtOption)
self.lab_current1 = Label(text="")
self.add_widget(self.lab_current1)
self.lab_current = Label(text="Current",font_size=16)
self.add_widget(self.lab_current)
self.txtCurrent = TextInput(font_size=16)
self.add_widget(self.txtCurrent)
#self.txtCurrent.text = PcName
self.lab_target1 = Label(text="")
self.add_widget(self.lab_target1)
self.lab_target = Label(text="Target",font_size=16)
self.add_widget(self.lab_target)
self.txtTarget = TextInput(font_size=16)
self.add_widget(self.txtTarget)
self.lab_target2 = Label(text="")
self.add_widget(self.lab_target2)
self.lab_target3 = Label(text="")
self.add_widget(self.lab_target3)
self.btnSubmit = Button(text="Submit")
self.btnSubmit.bind(on_press=self.Kite_Auto)
self.add_widget(self.btnSubmit)
def buy_button_click(self,instance):
print(instance.text)
self.txtOption.text = instance.text
def Kite_Auto(self,instance):
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
dir_path = os.path.dirname(os.path.realpath(__file__))
#Update Selenium chrome driver folder path here
chromedriver = dir_path + "/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chrome_options=options, executable_path= chromedriver)
driver.get("https://kite3.zerodha.com")
driver.maximize_window()
Crudoil = 0
target = float(self.txtTarget.text)
while Crudoil==0:
element = WebDriverWait(driver, 10000).until(EC.presence_of_element_located((By.XPATH, "//*[@id='app']/div[2]/div[1]/div/div[2]/div/div/div/div/span[2]/span[3]")))
Current_AMount = element.text
LCurrent= float(Current_AMount)
self.txtCurrent.text = Current_AMount
if LCurrent>=target and self.txtOption.text == "Buy":
replyV = pymsgbox.alert(text='Buy Target Achieved! - ' + str(LCurrent), title='', button='OK')
print(replyV)
break
if LCurrent<=target and self.txtOption.text == "Sell":
replyV = pymsgbox.alert(text='Sell Target Achieved! - ' + str(LCurrent), title='', button='OK')
print(replyV)
break
class Kite_Zerodha(App):
def build(self):
return Kite()
if __name__ == "__main__":
Kite_Zerodha().run()
Comments
Post a Comment