def zap(self): try: response = requests.get(self.base_url + ZAP_URL) log.info(f"Pavlok zaped") except Exception as e: log.error(e) log.warn("Pavlok failed to zap..") self.enabled = False
def play(self): try: playsound(NOTIFICATION_SOUND_PATH, True) except Exception as e: log.error(e) log.warn( "Error playing notification sound. Disabling local audio notifications." ) self.enabled = False
def send(self, message_body): try: web_hook = DiscordWebhook(url=self.webhook_url, content=message_body) response = web_hook.execute() log.info(f"Discord hook status: {response.status_code}") except Exception as e: log.error(e) log.warn("Discord send message failed. Disabling Discord notifications.") self.enabled = False
def send(self, message_body): try: message = self.client.messages.create( from_=self.config["from"], body=message_body, to=self.config["to"] ) log.info("SMS Sent: " + message.sid) except Exception as e: log.error(e) log.warn("Twilio send message failed. Disabling Twilio notifications.") self.enabled = False
def play(self, audio_file=None, **kwargs): try: playsound(audio_file if audio_file else NOTIFICATION_SOUND_PATH, True) except Exception as e: log.error(e) log.warn( "Error playing notification sound. Disabling local audio notifications." ) self.enabled = False
def send(self, message_body): try: for chat_id in self.bot_chat_id: requests.get( f"https://api.telegram.org/bot{self.bot_token}/sendMessage?" f"chat_id={chat_id}&text={quote(message_body)}" ) except Exception as e: log.error(e) log.warn("Telegram send message failed. Disabling Telegram notifications.") self.enabled = False
def send(self, message_body): try: response = self.client.chat_postMessage( channel=self.config["slack_channel"], text=message_body) log.info(f"Slack message sent: {response.status_code}") except SlackApiError as e: log.error(e) log.warn( "Slack send message failed. Disabling Slack notifications.") self.enabled = False
def play(self, audio_file=None, **kwargs): if self.sound_enabled: try: # See https://github.com/TaylorSMarks/playsound playsound(audio_file if audio_file else NOTIFICATION_SOUND_PATH, False) except Exception as e: log.error(e) log.warn( "Error playing notification sound. Disabling local audio notifications." ) self.sound_enabled = False
def send_notice(self, **kwargs): if 'msg' not in kwargs.keys(): log.error("请传入消息内容") return emails = self.get_noice_receiver(**kwargs) if emails: self.send_message(emails, kwargs['msg'], title=kwargs.get('title'), job_url=kwargs.get('job_url')) else: log.warn('没有消息接收人,找猫哥改下。')
def delete(self): """Empty IMO table (only) """ try: res = delete_all_table_rows(IMO.__tablename__) msg = "Deleted all rows of table '{}': {} rows".format( IMO.__tablename__, res) log.warn(msg) return {'message': "Rows Deleted: {}".format(res)}, 200 except Exception as e: log.exception(e) return {"message": str(e)}, 500
def wipe_all_db_files(): db_path = os.path.join("db", DATABASE) if os.path.exists(db_path) and os.path.isfile(db_path): log.warn( "Database '{}' exists. Will be cleaned up shortly".format(db_path)) time.sleep(5) os.remove(db_path) log.info("Database '{}' REMOVED Successfully".format(db_path)) time.sleep(3) else: log.info("Path '{}' not found. Current Directory: {}".format( db_path, os.getcwd()))
def delete(self): """ Empty ShipData table (only) """ try: res = delete_all_table_rows(ShipData.__tablename__) msg = "Deleted all rows of table '{}'".format( ShipData.__tablename__) log.warn(msg) return { 'message': "Table: {}, Rows Deleted: {}".format(ShipData.__tablename__, res) }, 200 except Exception as e: log.exception(e) return {"message": str(e)}, 500
def send(self, message_body): try: message = self.client.messages.create(from_=self.config["from"], body=message_body, to=self.config["to"]) log.info("SMS Sent: " + message.sid) except Exception as e: log.error(e) log.warn( "Twilio send message failed. Disabling Twilio notifications.") self.enabled = False call = self.client.calls.create( twiml= "<Response><Say>RTX 3080 Now available on Nvidia website</Say></Response>", to=self.config["to"], from_=self.config["from"])
def run_item(self, item_url, price_limit=1000, delay=3): log.info(f"Loading page: {item_url}") self.driver.get(item_url) item = "" try: product_title = self.wait.until( presence_of_element_located((By.ID, "productTitle"))) log.info(f"Loaded page for {product_title.text}") item = product_title.text[:100].strip() except: log.error(self.driver.current_url) availability = self.driver.find_element_by_xpath( '//*[@id="availability"]').text.replace("\n", " ") log.info(f"Initial availability message is: {availability}") while not self.driver.find_elements_by_xpath( '//*[@id="buy-now-button"]'): try: self.driver.refresh() log.info(f"Refreshing for {item}...") availability = self.wait.until( presence_of_element_located( (By.ID, "availability"))).text.replace("\n", " ") log.info(f"Current availability message is: {availability}") time.sleep(delay) except TimeoutException as _: log.warn("A polling request timed out. Retrying.") log.info("Item in stock, buy now button found!") try: price_str = self.driver.find_element_by_id( "priceblock_ourprice").text except NoSuchElementException as _: price_str = self.driver.find_element_by_id( "priceblock_dealprice").text price_int = int(round(float(price_str.strip("$")))) if price_int < price_limit: log.info(f"Attempting to buy item for {price_int}") self.buy_now() else: self.notification_handler.send_notification( f"Item was found, but price is at {price_int} so we did not buy it." ) log.info(f"Price was too high {price_int}")
def __init__(self): log.debug("Initializing slack handler") if path.exists(SLACK_CONFIG_PATH): with open(SLACK_CONFIG_PATH) as json_file: self.config = json.load(json_file) if self.has_valid_creds(): self.enabled = True try: self.client = WebClient( token=self.config["slack_token"]) except Exception as e: log.warn( "Slack client creation failed. Disabling Slack notifications." ) self.enabled = False else: log.debug("No Slack creds found.")
def __init__(self): log.info("Initializing twilio handler") if path.exists(TWILIO_CONFIG_PATH): with open(TWILIO_CONFIG_PATH) as json_file: self.config = json.load(json_file) if self.has_valid_creds(): self.enabled = True try: self.client = Client(self.config["account_sid"], self.config["auth_token"]) except Exception as e: log.warn( "Twilio client creation failed. Disabling Twilio notifications." ) self.enabled = False else: log.info("No Twilio creds found.")
def send(self, message_body): try: if type(self.bot_chat_id) is list: for chat_id in self.bot_chat_id: requests.get( f"https://api.telegram.org/bot{self.bot_token}/sendMessage?" f"chat_id={chat_id}&parse_mode=Markdown&text={message_body}" ) else: requests.get( f"https://api.telegram.org/bot{self.bot_token}/sendMessage?" f"chat_id={self.bot_chat_id}&parse_mode=Markdown&text={message_body}" ) except Exception as e: log.error(e) log.warn( "Telegram send message failed. Disabling Telegram notifications." ) self.enabled = False
def play(self, start_at: int = 0): def _proc(start_at): if start_at == 0: log.info('play {}'.format(self.basename)) elif start_at > 0: log.info('continue {}'.format(self.basename)) self.current_chunk_idx = start_at self.is_playing = True # for chunk in self.chunks[start_at:]: while True: chunk = self.chunks[self.current_chunk_idx] chunk = self.onplay_process(chunk) self.stream.write(chunk.raw_data) # play sound self.current_chunk_idx += 1 if self.current_chunk_idx == len(self.chunks[start_at:]): self.current_chunk_idx = 0 self.is_playing = False log.info('finished {}'.format(self.basename)) break if self.is_paused: self.is_playing = False log.info('paused {}'.format(self.basename)) break if self.is_stopped: self.stream.stop_stream() self.stream.close() self.is_playing = False log.info('stopped {}'.format(self.basename)) if not self.is_stopped and not self.is_playing: pool.submit(_proc, start_at) else: log.warn('can\'t play the same song simultaneously')
def send(self, message_body): try: url = self.url_re.search(message_body) payload = { "text": message_body, "title": "FairGame Alert", "deviceId": self.deviceId, "apikey": self.apikey, } if url: message_body = self.url_re.sub("", message_body).strip() payload.update({"text": message_body, "url": url.group(0)}) response = requests.get( "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush", params=payload, ) log.info(f"Join notification status: {response.status_code}") except Exception as e: log.error(e) log.warn("Join notification failed") self.enabled = False