-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.py
70 lines (52 loc) · 2.46 KB
/
message.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
"""
author: Mookeun Ji, goofcode@gmail.com
Functions defined here may raise some exceptions from driver in case of
1. setting or locator fault
2. loss of internet connection
3. ==unknown change in kakao web==
4. ==unusual notice==
So, if there is any issue,
going through whole messaging process manually on actual browser at least once and
modifying this set of codes appropriately are recommended for further use
"""
from .util import *
def send_basic_text_message(content, time=None, link=None, share=True, mode='phantom'):
"""
send basic text type message to all friends
:param content: message content to be sent
:param [opt] time: time message to be sent(formatted as yyyymmdd hh:mm, if none, time set to be now
:param [opt] link: link to be sent w/ message if none, only content will be send
:param [opt] share: whether enable 'share to friend'
:param [opt] mode: 'chrome' or 'phantom'(headless)
"""
driver = None
try:
driver = get_driver(mode)
settings, locators = get_settings_and_locators()
login_pf_center(driver)
driver.get(url_join(settings['pf_home_url'], locators['basic_message_url']))
# fill inputs for new message
wait_until_load(driver, 'id', locators['message_input_id']).send_keys(content)
if link is not None:
wait_until_load(driver, 'xpath', locators['add_link_radio_xpath']).click()
wait_until_load(driver, 'id', locators['link_name_id']).send_keys("바로가기")
wait_until_load(driver, 'id', locators['link_input_id']).clear()
wait_until_load(driver, 'id', locators['link_input_id']).send_keys(link)
if share is False:
wait_until_load(driver, 'xpath', locators['no_share_radio_xpath']).click()
wait_until_load(driver, 'xpath', locators['next_btn_xpath']).click()
'''
TODO : add time feature
if time is not None:
d_time = datetime.datetime.strptime(time, '%Y%m%d %H:%M')
wait_until_load(driver, 'class', locators['show_calendar_class']).click()
'''
wait_until_load(driver, 'xpath', locators['submit_btn_xpath']).click()
wait_until_load(driver, 'xpath', locators['confirm_btn_xpath']).click()
except Exception as ex:
if driver is not None:
driver.save_screenshot('screenshot.png')
driver.close()
raise ex
if driver is not None:
driver.close()