-
Notifications
You must be signed in to change notification settings - Fork 234
/
tgscreenshot_share.py
90 lines (67 loc) · 2.53 KB
/
tgscreenshot_share.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from selenium import webdriver
import time
import telegram
import io
from PIL import Image
import datetime
bot_token = 'your bot token'
chat_id = -000000
bot = telegram.Bot(token=bot_token)
def get_screenshot(userid, passwd, pin, scrollby):
driverpath = "C:\\chromedrive\\chromedriver.exe" #TODO set path of chromedriver
options = webdriver.ChromeOptions()
from io import BytesIO
options.add_argument("--start-maximized")
driver = webdriver.Chrome(executable_path=driverpath, chrome_options=options)
driver.set_window_size(1920, 1080)
driver.get('https://kite.zerodha.com/positions')
time.sleep(5)
username = driver.find_element_by_css_selector('input[type=text]')
password = driver.find_element_by_css_selector('input[type=password]')
try:
username.send_keys(userid)
except Exception as e:
print(e)
try:
password.send_keys(passwd)
except Exception as e:
print(e)
try:
driver.find_element_by_css_selector('button[type=submit]').click()
time.sleep(2)
except Exception as e:
print(e)
time.sleep(5)
try:
password = driver.find_element_by_css_selector('input[type=password]')
password.send_keys(pin)
time.sleep(1)
driver.find_element_by_css_selector('button[type=submit]').click()
except Exception as e:
print(e)
time.sleep(3)
try :
if scrollby == 600 :
driver.execute_script("scrollBy(0,600);")
else:
driver.execute_script("scrollBy(0,25000);")
except Exception as e :
print(e)
time.sleep(3)
path = "C:\\db\\livetradedata\\screenshot\\screenshot.png" # TODO set path to save screetshot on drive
path2 = "C:\\db\\livetradedata\\screenshot\\{}.png".format(datetime.datetime.today().strftime("%Y%m%d%H%M%S"))
driver.save_screenshot(path)
driver.save_screenshot(path2)
bio = BytesIO()
image = Image.open(path, mode='r')
width, height = image.size
image = image.crop((0, 50, width, height))
image = image.convert('RGB')
bio.name = 'image.jpeg'
image.save(bio, 'JPEG')
bio.seek(0)
bot.send_photo(chat_id, photo=bio, caption="{}".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")))
time.sleep(10)
driver.quit()
get_screenshot("Userid","Password",000000, 600) # zerodha userid password and pin
get_screenshot("Userid","Password",000000, 0) # zerodha userid password and pin