def send_now(app_key, request): app = Application(key=app_key).auth() message = request.args.get('message')[0] sound = request.args.get('sound')[0] or 'default' badge = request.args.get('badge') or 0 token = request.args.get('token')[0] extra = request.args.get('extra')[0] request.setHeader('Content-Type', 'application/json') content = dict(alert=message, sound=sound, badge=badge, extra=json.loads(extra)) if app: log.msg('application found: %s' % app.name) notification = Notification(token=token, app=app, content=content) notification.send() else: log.msg('No application found with key %s' % app_key[1], logLevel=logging.WARNING) yield 'OK'
def __init__(self, cmd_id, sender, recipients, email, data): Notification.__init__(self) self.title = "@CMD: %s" % (cmd_id) self.sender = sender self.recipients = recipients self.body["text"] = self.__get_body(email, data.raw)
def __init__(self, cmd_id, sender, recipients, email, data): Notification.__init__(self) self.title = "@CMD: %s" % (cmd_id) self.sender = sender self.recipients = recipients self.body["text"] = self.__get_body(email, data.raw)
def test_notification(self): notification = Notification() notification.title = "Test" notification.sender = "*****@*****.**" notification.recipients.append("*****@*****.**") notification.body["text"] = "JOJOJOJO" self.notifier.send(notification)
def test_notification(self): notification = Notification() notification.title = "Test" notification.sender = "*****@*****.**" notification.recipients.append("*****@*****.**") notification.body["text"] = "JOJOJOJO" self.notifier.send(notification)
def add_like_to_sheet(sheet_id, uid): """ Add uid as a liker of sheet_id. """ db.sheets.update({"id": sheet_id}, {"$addToSet": {"likes": uid}}) sheet = get_sheet(sheet_id) notification = Notification(uid=sheet["owner"]) notification.make_sheet_like(liker_id=uid, sheet_id=sheet_id) notification.save()
def __init__(self, sender, recipients, command, sprops): Notification.__init__(self) if "subject" in sprops: self.title = sprops["subject"] else: self.title = "Re: " + command.id if "reply-to" in sprops: recipients.append(sprops["reply-to"]) self.recipients = recipients self.sender = sender self.body = command.output
def __init__(self, sender, recipients, command, sprops): Notification.__init__(self) if "subject" in sprops: self.title = sprops["subject"] else: self.title = "Re: " + command.id if "reply-to" in sprops: recipients.append(sprops["reply-to"]) self.recipients = recipients self.sender = sender self.body = command.output
def __new_flight__(self, flight_id: int, username: str, depart: str, dest: str, depart_date: str, flight_type: str, return_date: Optional[str] = None): """ Creates a basic flight instance, its table, and its dict. :param flight_id: :param username: :param depart: :param dest: :param depart_date: :param flight_type: :param return_date: :return: COMMENT: need to increment flight_id by 1 in load_app """ self.username = username self.flight_id = flight_id self.table_name = 'tb_' + str(flight_id) self.flight_type = flight_type self.depart = depart self.dest = dest self.depart_date = depart_date self.return_date = return_date # Create table and dicts mydb = mysql.connector.connect(host='localhost', user='******', passwd='flightplanner', database='FP_database') mycursor = mydb.cursor() set_up_command = 'CREATE TABLE {0} (Flight_id int, Date varchar(255), Min_eco int, Min_bus int, Avg_econ int,' \ ' Avg_bus int, Track_date varchar(255));'.format(self.table_name) mycursor.execute(set_up_command) mydb.commit() mycursor.close() self.info_dict = dict() self.filters = Filters() self.filters.require_filters() self.notifications = Notification() self.notifications.require_notifications()
def notify_manual_close(self, event): sunrise_sunset = event.kwargs.get('sunrise_sunset') self.coop.notifier_callback( Notification('WARN', '{name} is in manual mode and is closed{at}!', name=self.name, at=(' during the day' if sunrise_sunset and sunrise_sunset.is_day() else '')))
def notify_temp_error_low(self): self.coop.notifier_callback( Notification( 'ERROR', '{name} - temperature {temp:.1f} is below {mini:.1f} minimum', name=self.name, temp=self.temp, mini=self.temp_error_low))
def notify_temp_error_high(self): self.coop.notifier_callback( Notification( 'ERROR', '{name} - temperature {temp:.1f} is above {maxi:.1f} maximum', name=self.name, temp=self.temp, maxi=self.temp_error_high))
def main(): db = PersistentDict() checker = UpdateChecker(host='oldschool78.runescape.com') initial_revision = db['revision'] or 140 if type(initial_revision) is str: initial_revision = int(initial_revision) current = checker.run(start=initial_revision) if current is not None: db['revision'] = current if current != initial_revision: n = Notification(title='OSRS Updated!', body='New revision={}, Old revision={}'.format(current, initial_revision)) send_notification(n)
def send_now(app_key, request): app = Application(key=app_key).auth() message = request.args.get('message')[0] sound = request.args.get('sound')[0] or 'default' badge = request.args.get('badge') or 0 token = request.args.get('token')[0] extra = request.args.get('extra')[0] request.setHeader('Content-Type', 'application/json') content = dict(alert=message, sound=sound, badge=badge, extra=json.loads(extra)) if app: log.msg('application found: %s' % app.name) notification = Notification(token=token, app=app, content=content) notification.send() else: log.msg('No application found with key %s' % app_key[1], logLevel=logging.WARNING) yield 'OK'
def turn_off(self, event=None): self.relay.turn_off() extra_info = '' if event and 'temp' in event.kwargs: temp = event.kwargs.get('temp') extra_info = ' (temp={:.1f})'.format(temp) if temp else '???' self.coop.notifier_callback( Notification( 'INFO', '{name} turned off{auto}{extra_info}', name=self.name, auto=('' if self.is_manual_mode() else ' automatically'), extra_info=extra_info))
def main(): if len(sys.argv) < 2: print('Usage: app.py urls.txt ') sys.exit(1) feed_rss_path = sys.argv[1] feed_rss_file = open("./" + feed_rss_path, "r") feed_rss_read = feed_rss_file.read() feed_rss_list = feed_rss_read.split('\n') feed_rss_file.close() for i in range (len(feed_rss_list)): feed_rss = feed_rss_list[i] net = Network(feed_rss) updates = net.headlines() for update in updates: new_notification = Notification() nw = new_notification.notify(app, icon_path, urgency) soup = BeautifulSoup(update['description'], features="html.parser") description = soup.get_text() nw.update(update['title'].upper(), description, icon_path) nw.show() time.sleep(60)
def get_notifications(): """ Gets the list of notifications of the current user :return: The list of notifications of the current user """ # type: () -> list() notifications = list() data = jsonM.get_from_url('https://api.picarto.tv/v1/user/notifications') if data is not None: for notification in data: notifications.append(Notification(notification)) return notifications
def __init__(self): print("#> INITIALIZING STOCK API PIPELINE ") [self.sell,self.buy,self.trade] = [SellingConditions(),TradingConditions(),BuyingConditions()] self.notif = Notification() self.prev_hist = {} self.complist = pd.Series( open("symbols.txt", "r").readlines() ) # self.complist = pd.read_csv('companylist.csv') tolower = lambda x: x.lower().strip() # self.tickers = ['msft'] self.db = Connection() self.tickers = self.complist.apply( tolower ) th = Thread(target = self.main, args = ()) th.daemon = True th.start() print("### STOCK API PIPELINE RUNNING ON %s " % th)
def GET(self): super(Reboot, self).GET() username, _ = get_username_password( web.ctx.env.get('HTTP_AUTHORIZATION')) coop = Coop() coop.rebooting = True coop.notifier_callback( Notification('WARN', 'Reboot initiated by user {username}', username=username)) coop.stop() coop.join() coop.shutdown() call(['/usr/bin/sudo', '/sbin/shutdown', '-r', 'now']) raise web.seeother('/')
def close(self, event): switches = event.kwargs['switches'] if switches.state == 'closed': log.info('{} was already closed'.format(self.name)) return self.turn_on(0) closed = switches.bottom_sensor.wait_on() # delay to compensate for switches sometimes trigerring too soon sleep(0.1) self.turn_off(0) if not closed: switches.bottom_sensor.failed_to_wait() self.coop.notifier_callback( Notification('ERROR', '{name} failed to close{at}', name=self.name, at=(' at sunset' if self.is_auto_mode() else ''))) self.set_manual() else: self.coop.notifier_callback( Notification('INFO', '{name} closed{at}', name=self.name, at=(' at sunset' if self.is_auto_mode() else '')))
def open(self, event): switches = event.kwargs['switches'] if switches.state == 'open': log.info('{} was already open'.format(self.name)) return self.turn_on(1) opened = switches.top_sensor.wait_on() self.turn_off(1) if not opened: switches.top_sensor.failed_to_wait() self.coop.notifier_callback( Notification( 'ERROR', '{name} failed to open{at}', name=self.name, at=(' at sunrise' if self.is_auto_mode() else ''))) self.set_manual() else: self.coop.notifier_callback( Notification( 'INFO', '{name} opened{at}', name=self.name, at=(' at sunrise' if self.is_auto_mode() else '')))
def __load_flight__(self, flight_id: int, flight: Flight): """ loads a flight object by obtaining into from general DB :param flight_id: :param flight: :return: """ info_tuple = self.flights_db.flights_dict[flight_id] # load into flight object flight.username = info_tuple[0] flight.flight_type = info_tuple[1] flight.depart = info_tuple[2] flight.dest = info_tuple[3] flight.depart_date = info_tuple[4] flight.return_date = info_tuple[5] flight.table_name = 'tb_' + str(flight_id) flight.flight_id = flight_id temp_filter = Filters() temp_filter.insert_day_filter(info_tuple[6]) temp_filter.insert_depart_time_filter(info_tuple[7]) temp_filter.insert_max_duration_filter(info_tuple[8]) temp_filter.insert_price_amount_filter(info_tuple[9]) flight.filters = temp_filter temp_noti = Notification() if info_tuple[10] != "NULL": limit_min = info_tuple[10].split(';')[0] limit_max = info_tuple[10].split(':')[1] temp_noti.insert_amount(limit_min, limit_max) if info_tuple[11] != "NULL": temp_noti.insert_diff(int(info_tuple[11])) if info_tuple[12] != "NULL": days_since_reset = info_tuple[12].split(';')[0] inc_num = info_tuple[12].split(';')[1] direction = info_tuple[12].split(';')[2] temp_noti.insert_trend(days_since_reset, inc_num, direction) flight.notifications = temp_noti
def validate_user(ctx, notify=False): if not ctx.env.get('HTTP_AUTHORIZATION'): return False username, password = get_username_password( ctx.env.get('HTTP_AUTHORIZATION')) coop = Coop() if username == coop.config['Authentication'][ 'USERNAME'] and password == coop.config['Authentication'][ 'PASSWORD']: return True else: if notify: coop.notifier_callback( Notification( 'WARN', 'Failed login attempt: username={username}, password={password}, ip={ip}', username=username, password=password, ip=ctx['ip'])) return False
from functions import Functions from user import User from log import Log from employees import Employees from notifications import Notification from purchase_request import PurchaseRequest from abstract_of_canvass import AbstractOfCanvass from suppliers import Suppliers from property_acc_receipt import PropertyAcceptanceReceipt from key_positions import KeyPositions f = Functions() u = User() l = Log() e = Employees() n = Notification() preq = PurchaseRequest() abc = AbstractOfCanvass() supp = Suppliers() prop = PropertyAcceptanceReceipt() kp = KeyPositions() def index(request): loopRef = genLoopRangeString(5, [('rr', 'tt', 'yy', 'uu'), ('ii', 'qq', 'ww'), ('ss', 'dd')]) return setReponse(request, 'non_requisitioner/index.html', [('rr', 'tt', 'yy', 'uu'), ('ii', 'qq', 'ww'), ('ss', 'dd')], [ (loopRef, ),
def notify_half(self): self.coop.notifier_callback( Notification('WARN', '{name} - water tank is low', name=self.name))
def notify_empty(self): self.coop.notifier_callback( Notification('ERROR', '{name} - water tank is empty', name=self.name))
class Flight: def __init__(self): """ return a new, empty flight object. """ self.username = None self.flight_id = 0 self.table_name = 'tb_' + str(self.flight_id) self.info_dict = dict() self.flight_type = None self.depart = None self.dest = None self.depart_date = None self.return_date = None self.filters = None self.notifications = None # store an object information in table general_info def __new_flight__(self, flight_id: int, username: str, depart: str, dest: str, depart_date: str, flight_type: str, return_date: Optional[str] = None): """ Creates a basic flight instance, its table, and its dict. :param flight_id: :param username: :param depart: :param dest: :param depart_date: :param flight_type: :param return_date: :return: COMMENT: need to increment flight_id by 1 in load_app """ self.username = username self.flight_id = flight_id self.table_name = 'tb_' + str(flight_id) self.flight_type = flight_type self.depart = depart self.dest = dest self.depart_date = depart_date self.return_date = return_date # Create table and dicts mydb = mysql.connector.connect(host='localhost', user='******', passwd='flightplanner', database='FP_database') mycursor = mydb.cursor() set_up_command = 'CREATE TABLE {0} (Flight_id int, Date varchar(255), Min_eco int, Min_bus int, Avg_econ int,' \ ' Avg_bus int, Track_date varchar(255));'.format(self.table_name) mycursor.execute(set_up_command) mydb.commit() mycursor.close() self.info_dict = dict() self.filters = Filters() self.filters.require_filters() self.notifications = Notification() self.notifications.require_notifications() def __load_flight_dict__(self): """ loads the flight's dictionary from flight table. Track_date as key in dict. :return: a flight object with loaded dict. """ mydb = mysql.connector.connect(host='localhost', user='******', passwd='flightplanner', database='FP_database') mycursor = mydb.cursor() temp_dict = dict() mycursor.execute("SELECT * FROM {0};".format(self.table_name)) data_list = mycursor.fetchall() for record in data_list: temp_dict[record[6]] = record[:6] self.info_dict = temp_dict mycursor.close() def commit_flight_db(self, min_eco: int, min_bus: int, avg_econ: int, avg_bus: int): """ Updates both flight table and flight dict using newly extracted info from web. :param min_eco: :param min_bus: :param avg_econ: :param avg_bus: :return: """ mydb = mysql.connector.connect(host='localhost', user='******', passwd='flightplanner', database='FP_database') mycursor = mydb.cursor() record_command = "INSERT INTO {0} (Flight_id, Date, Min_eco, Min_bus, Avg_econ, Avg_bus, Track_date) VALUES" \ " ({1}, {2}, {3}, {4}, {5}, {6}, {7})".format(self.table_name, self.flight_id, self.depart_date, min_eco, min_bus, avg_econ, avg_bus, str(datetime.date.today())) mycursor.execute(record_command) mydb.commit() mycursor.close() # Now update the dict self.info_dict[str( datetime.date.today())] = (self.flight_id, self.depart_date, min_eco, min_bus, avg_econ, avg_bus)
def __init__(self, config, widget): self.config = config self.notification = Notification(widget) self.integration_status = None
def notify_manual(self, event): self.coop.notifier_callback( Notification('MANUAL', '{name} is on manual mode', name=self.name))
def notify_invalid(self): self.coop.notifier_callback( Notification('WARN', '{name} - unable to get sunrise/sunset data', name=self.name))
def notify_manual_invalid(self, event): self.coop.notifier_callback( Notification('WARN', '{name} is in invalid state, set to manual mode', name=self.name))
def notify_night(self): self.coop.notifier_callback( Notification('INFO', '{name} - sunset at {sunset}', name=self.name, sunset=self.get_sunset()))
def notify_day(self): self.coop.notifier_callback( Notification('INFO', '{name} - sunrise at {sunrise}', name=self.name, sunrise=self.get_sunrise()))
def notify_invalid(self): self.coop.notifier_callback( Notification('ERROR', '{name} - water tank sensors are in invalid state', name=self.name))
def add(u_id=-1, type="", o_user = 0, o_info = "", r_id = 0): if u_id != -1 and type != "": #Notification creation o_user_name = User.get_name(o_user) verify = False if type == "GROUPINVITE": #Group invitation for a User u_g = UserGroupMgmt.get_by_id(r_id) if u_g: relevant = Group.get_name(u_g.group_id) notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = r_id, message = o_user_name + " has invited you to the group " + relevant + ".") notify.put() verify = True elif type == "GROUPACCEPT": #Informs Group Founder of accepted invite relevant = Group.get_name(r_id) notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = r_id, message = o_user_name + " has accepted your invitation to the group " + relevant + ".") notify.put() verify = True elif type == "GROUPREJECT": #Informs Group Founder of rejected invite relevant = Group.get_name(r_id) notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = r_id, message = o_user_name + " has rejected your invitation to the group " + relevant + ".") notify.put() verify = True elif type == "GROUPLEAVE": #Informs Group Founder of a member who has left the Group relevant = Group.get_name(r_id) notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = r_id, message = o_user_name + " has left the group " + relevant + ".") notify.put() verify = True elif type == "GROUPJOINCFM": #Confirms to a User they have joined a Group relevant = Group.get_name(r_id) notify = Notification(user_id = u_id, notification_type = type, other_user = 0, relevant_id = r_id, message = "You have joined the group " + relevant + ".") notify.put() verify = True elif type == "GROUPPASSFOUNDER": #Informs User they are now the Founder of a Group relevant = Group.get_name(r_id) notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = r_id, message = o_user_name + " has made you the Founder of the group " + relevant + ".") notify.put() verify = True elif type == "GROUPEXPEL": #Informs User they have been expelled from a Group relevant = Group.get_name(r_id) notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = r_id, message = o_user_name + " has kicked you from the group " + relevant + ".") notify.put() verify = True elif type == "GROUPDELETE": #Informs all Users in a Group of its deletion notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = 0, message = o_user_name + " has deleted the group " + o_info + ".") notify.put() verify = True elif type == "GROUPDELCANCEL": #Informs a User pending an invite that said Group was deleted notify = Notification(user_id = u_id, notification_type = type, other_user = o_user, relevant_id = 0, message = o_user_name + " has cancelled your invite and deleted the group " + o_info + ".") notify.put() verify = True elif type == "ADMINDELETE": #Informs a User that an administrator has deleted their sketch notify = Notification(user_id = u_id, notification_type = type, other_user = 0, relevant_id = 0, message = "An administrator has deleted your sketch '" + o_info + "'.") notify.put() verify = True return verify
def notify_auto(self, event): self.coop.notifier_callback( Notification('INFO', '{name} is back to automatic mode', name=self.name))