-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipoRequest.py
124 lines (96 loc) · 4.6 KB
/
ipoRequest.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import datetime
import sys
from selenium.common.exceptions import WebDriverException
from slack_bot import Slack
from seleniumUtils import SeleniumUtils
from fileUtils import FileUtils
class IpoRequest():
def __init__(self):
self.driver = SeleniumUtils.getChromedriver(__file__)
self.applyCount = 0
self.IPO_REQ_BUTTON_SELECTOR = "a[name] + table .fl01 a img[alt='申込']"
# all member login info
config = FileUtils.open_file(__file__, "/config.json")
self.login_info_list = config["sbis_login_info"]
def ipo_request(self):
driver = self.driver
slack = Slack()
try:
# SBI securities page
driver.get("https://www.sbisec.co.jp/ETGate")
for login_info in self.login_info_list:
self.one_person_ipo_request(driver, login_info)
# slack notice
message = "everyone's ipo applied num:" + str(self.applyCount)
slack.post_message_to_channel("general", message)
except WebDriverException:
import traceback
message = "occurred system error!!\n" + str(traceback.print_exc())
slack.post_message_to_channel("general", message)
finally:
driver.close()
def one_person_ipo_request(self, driver, login_info):
driver.find_element_by_name("user_id").send_keys(login_info["uid"])
driver.find_element_by_name(
"user_password").send_keys(login_info["upa"])
driver.find_element_by_name("ACT_login").click()
# open IPO apply page
driver.find_element_by_xpath('//*[@id="navi01P"]/ul/li[3]').click()
driver.find_element_by_xpath('//*[@id="navi02P"]/ul/li[5]').click()
driver.find_element_by_xpath('//*[@id="main"]/div[10]/div/div').click()
# apply IPO
stock_tables = driver.find_elements_by_css_selector("a[name]+table")
if not stock_tables:
sys.exit()
apply_stock_tables = self.createApplyStTbls(stock_tables)
if not apply_stock_tables:
# remove commentout if you fail on the way, commmentout sys.exit()
sys.exit()
# driver.find_element_by_xpath('//*[@id="logoutM"]/a/img').click()
# driver.find_element_by_xpath('//*[@id="navi01P"]/ul/li[1]/a/img').click()
# return
stock_len = len(apply_stock_tables)
mostReceStockTbl = apply_stock_tables[stock_len - 1]
stockInfoTds = mostReceStockTbl.find_elements_by_css_selector(".fl01")
# do commentout below two line if you fail on the way
# if not self.isIpoApplyExec(stockInfoTds):
# sys.exit()
stock_reqbtns = driver.find_elements_by_css_selector(self.IPO_REQ_BUTTON_SELECTOR)
while(stock_reqbtns):
stock_reqbtns[0].click()
# input application contents
driver.find_element_by_name("suryo").send_keys(3000) # request num
driver.find_element_by_xpath("//*[@id='strPriceRadio']").click()
driver.find_element_by_name("useKbn").send_keys(0)
driver.find_element_by_name("usePoint").send_keys("")
driver.find_element_by_name(
"tr_pass").send_keys(login_info["uspa"])
driver.find_element_by_name("order_kakunin").click()
# fixed apply
driver.find_element_by_name("order_btn").click()
driver.find_element_by_css_selector(
".mtext a[href='/oeliw011?type=21']").click()
self.applyCount += 1
stock_reqbtns = driver.find_elements_by_css_selector(self.IPO_REQ_BUTTON_SELECTOR)
# logout
driver.find_element_by_xpath('//*[@id="logoutM"]/a/img').click()
driver.find_element_by_xpath(
'//*[@id="navi01P"]/ul/li[1]/a/img').click()
def createApplyStTbls(self, stock_tables):
applyStTbls = []
for table in stock_tables:
if table.find_elements_by_css_selector(self.IPO_REQ_BUTTON_SELECTOR):
applyStTbls.append(table)
return applyStTbls
def isIpoApplyExec(self, stockInfoTds):
strApplyEndDate = stockInfoTds[3].text.split("~")[1].split(" ")[0]
applyEndMon = int(strApplyEndDate.split("/")[0])
applyEndDay = int(strApplyEndDate.split("/")[1])
d_now = datetime.date.today()
year_now = d_now.year
applyEndDate = datetime.date(year_now, applyEndMon, applyEndDay)
# when today is two days ago most recent apply date, execute application
return applyEndDate >= d_now - datetime.timedelta(days=2)
if __name__ == "__main__":
ipoRequest = IpoRequest()
ipoRequest.ipo_request()