tradezero_api.notification
1from __future__ import annotations 2 3from selenium.webdriver.common.by import By 4 5from .time_helpers import Time 6 7 8class Notification(Time): 9 """A class for retrieving notifications from the web-app""" 10 11 def __init__(self, driver): 12 self.driver = driver 13 14 def get_last_notification_message(self): 15 """ 16 return last notification message 17 18 :return: str 19 """ 20 return self.driver.find_element(By.CSS_SELECTOR, 'span.message').text 21 22 def get_notifications(self, notif_amount: int = 1): 23 """ 24 return a nested list with each sublist containing [time, title, message], 25 note that u can only view the amount of notifications that are visible in the box/widget 26 without scrolling down (which usually is around 6-9 depending on each message length) 27 example of nested list: (see the docs for a better look): 28 [['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'], 29 ['11:23:34', 'Level 2', 'You are not authorized for symbol: AMD'], 30 ['11:23:34', 'Error', 'You are not authorized for symbol: AMD']]. 31 32 :param notif_amount: int amount of notifications to retrieve sorted by most recent 33 :return: nested list 34 """ 35 notif_lst = self.driver.find_elements(By.XPATH, 36 '//*[@id="notifications-list-1"]/li') 37 notif_lst_text = [x.text.split('\n') for x in notif_lst[0:notif_amount] if x.text != ''] 38 39 notifications = [] 40 for (notification, i) in zip(notif_lst_text, range(notif_amount)): 41 if len(notification) == 2: 42 notification.insert(0, str(self.time)) 43 44 elif notification[0] == '' or notification[0] == '-': 45 notification[0] = str(self.time) 46 47 notifications.append(notification) 48 return notifications 49 50 def notifications_generator(self): 51 """ 52 A notification generator, similarly to get_notifications(), this yields one notification at a time, 53 on each next() it will yield a list like so: 54 ['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'] 55 You can think of it as a more dynamic version of get_notifications(), on each next(); it gets 56 one notification message. 57 58 :return: list 59 """ 60 notif_lst = self.driver.find_elements(By.XPATH, '//*[@id="notifications-list-1"]/li') 61 for item in notif_lst: 62 if item.text == '': 63 continue 64 65 notification = item.text.split('\n') 66 if len(notification) == 2: 67 notification.insert(0, str(self.time)) 68 69 elif notification[0] == '' or notification[0] == '-': 70 notification[0] = str(self.time) 71 72 yield notification
9class Notification(Time): 10 """A class for retrieving notifications from the web-app""" 11 12 def __init__(self, driver): 13 self.driver = driver 14 15 def get_last_notification_message(self): 16 """ 17 return last notification message 18 19 :return: str 20 """ 21 return self.driver.find_element(By.CSS_SELECTOR, 'span.message').text 22 23 def get_notifications(self, notif_amount: int = 1): 24 """ 25 return a nested list with each sublist containing [time, title, message], 26 note that u can only view the amount of notifications that are visible in the box/widget 27 without scrolling down (which usually is around 6-9 depending on each message length) 28 example of nested list: (see the docs for a better look): 29 [['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'], 30 ['11:23:34', 'Level 2', 'You are not authorized for symbol: AMD'], 31 ['11:23:34', 'Error', 'You are not authorized for symbol: AMD']]. 32 33 :param notif_amount: int amount of notifications to retrieve sorted by most recent 34 :return: nested list 35 """ 36 notif_lst = self.driver.find_elements(By.XPATH, 37 '//*[@id="notifications-list-1"]/li') 38 notif_lst_text = [x.text.split('\n') for x in notif_lst[0:notif_amount] if x.text != ''] 39 40 notifications = [] 41 for (notification, i) in zip(notif_lst_text, range(notif_amount)): 42 if len(notification) == 2: 43 notification.insert(0, str(self.time)) 44 45 elif notification[0] == '' or notification[0] == '-': 46 notification[0] = str(self.time) 47 48 notifications.append(notification) 49 return notifications 50 51 def notifications_generator(self): 52 """ 53 A notification generator, similarly to get_notifications(), this yields one notification at a time, 54 on each next() it will yield a list like so: 55 ['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'] 56 You can think of it as a more dynamic version of get_notifications(), on each next(); it gets 57 one notification message. 58 59 :return: list 60 """ 61 notif_lst = self.driver.find_elements(By.XPATH, '//*[@id="notifications-list-1"]/li') 62 for item in notif_lst: 63 if item.text == '': 64 continue 65 66 notification = item.text.split('\n') 67 if len(notification) == 2: 68 notification.insert(0, str(self.time)) 69 70 elif notification[0] == '' or notification[0] == '-': 71 notification[0] = str(self.time) 72 73 yield notification
A class for retrieving notifications from the web-app
15 def get_last_notification_message(self): 16 """ 17 return last notification message 18 19 :return: str 20 """ 21 return self.driver.find_element(By.CSS_SELECTOR, 'span.message').text
return last notification message
Returns
str
23 def get_notifications(self, notif_amount: int = 1): 24 """ 25 return a nested list with each sublist containing [time, title, message], 26 note that u can only view the amount of notifications that are visible in the box/widget 27 without scrolling down (which usually is around 6-9 depending on each message length) 28 example of nested list: (see the docs for a better look): 29 [['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'], 30 ['11:23:34', 'Level 2', 'You are not authorized for symbol: AMD'], 31 ['11:23:34', 'Error', 'You are not authorized for symbol: AMD']]. 32 33 :param notif_amount: int amount of notifications to retrieve sorted by most recent 34 :return: nested list 35 """ 36 notif_lst = self.driver.find_elements(By.XPATH, 37 '//*[@id="notifications-list-1"]/li') 38 notif_lst_text = [x.text.split('\n') for x in notif_lst[0:notif_amount] if x.text != ''] 39 40 notifications = [] 41 for (notification, i) in zip(notif_lst_text, range(notif_amount)): 42 if len(notification) == 2: 43 notification.insert(0, str(self.time)) 44 45 elif notification[0] == '' or notification[0] == '-': 46 notification[0] = str(self.time) 47 48 notifications.append(notification) 49 return notifications
return a nested list with each sublist containing [time, title, message], note that u can only view the amount of notifications that are visible in the box/widget without scrolling down (which usually is around 6-9 depending on each message length) example of nested list: (see the docs for a better look): [['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'], ['11:23:34', 'Level 2', 'You are not authorized for symbol: AMD'], ['11:23:34', 'Error', 'You are not authorized for symbol: AMD']].
Parameters
- notif_amount: int amount of notifications to retrieve sorted by most recent
Returns
nested list
51 def notifications_generator(self): 52 """ 53 A notification generator, similarly to get_notifications(), this yields one notification at a time, 54 on each next() it will yield a list like so: 55 ['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'] 56 You can think of it as a more dynamic version of get_notifications(), on each next(); it gets 57 one notification message. 58 59 :return: list 60 """ 61 notif_lst = self.driver.find_elements(By.XPATH, '//*[@id="notifications-list-1"]/li') 62 for item in notif_lst: 63 if item.text == '': 64 continue 65 66 notification = item.text.split('\n') 67 if len(notification) == 2: 68 notification.insert(0, str(self.time)) 69 70 elif notification[0] == '' or notification[0] == '-': 71 notification[0] = str(self.time) 72 73 yield notification
A notification generator, similarly to get_notifications(), this yields one notification at a time, on each next() it will yield a list like so: ['11:34:49', 'Order canceled', 'Your Limit Buy order of 1 AMD was canceled.'] You can think of it as a more dynamic version of get_notifications(), on each next(); it gets one notification message.
Returns
list