def admin_notification(request): if request.method == "GET": response_json = {} print( "===============Inside admin_notification GET method===============" ) for x, y in request.GET.items(): print("key,value", x, ":", y) title = str(request.GET.get('title')) time = str(request.GET.get('time')) date = str(request.GET.get('date')) message = str(request.GET.get('message')) notifications = NotificationData(notification_title=str(title), notification_date=str(date), notification_time=str(time), notification_message=str(message)) notifications.save() print("Notification row created") # for row in UserData.objects.all(): # if UserData.objects.filter(fcm=row.fcm).count() > 1: # row.delete() fcm_set = set() for user in UserData.objects.all(): try: fcm_set.add(user.fcm) except Exception as e: print("Exception " + str(e)) print(fcm_set) for item in fcm_set: try: send_notification(item, notifications.notification_message) except Exception as e: print("Exception....", e) return HttpResponseRedirect('/adminpanel/notification/')
def on_message(client, userdata, msg): print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic") data = json.loads(msg.payload) data["datetime"] = datetime.datetime.now() db.clean_air.update_one({"_id": 1}, {"$set": data}, upsert=True) print("Payload saved in the database") send_notification(data)
def ransom_fund_share(self, fund, money): application = RansomApplication( fund = fund, money = money, owner = self ) application.save() send_notification(recipient = fund.account.profile.user, verb = u'申请赎回份额', actor = self.profile.user, action = 'delete', target=application)
def transfer_money(self, transfer_to, money): money = Decimal(money) dec_money = money * Decimal(1.0001) self.check_assets(dec_money) self.dec_assets(dec_money) transfer_to.inc_assets(money) send_notification(recipient = transfer_to.profile.user, actor = self, verb = u'转帐给了', target = u'你') return TransferLog.objects.create( transfer_to = transfer_to, transfer_by = self, money = money )
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 finish(self, times = 1): rate = self.profit_rate / 100 total = Decimal(0) shares = self.shares.prefetch_related() for share in shares: money = share.money * (1+rate) ** times total += money share.owner.inc_assets(money) if self.type == self.ENTERPRISE: self.publisher.dec_assets(total) send_notification(recipient = self.publisher.profile.user, verb = u'已经结束了', actor = self) shares.delete() self.delete()
def create_offer(): user_id = request.form['user_id'] venue_id = request.form['venue_id'] time = request.form['time'] user = User.objects.get(fb_id=user_id) venue = Venue.objects.get(fs_id=venue_id) offer = Offer(initiator=g.user, party=user, venue=venue, time=time).save() # send notification here from notifications import send_notification send_notification(user.full_name, user.email, 'lunch-offer', { 'FNAME': user.first_name, 'PARTYNAME': '%s %s.' % (g.user.first_name, g.user.last_name[0]), 'VENUENAME': venue.name, 'TIME': time, 'ANSWERURL': get_home()}) return jsonify(offer_id=str(offer.id))
def accept_offer(offer_id): offer = Offer.objects.get(id=ObjectId(offer_id)) offer.accepted = True offer.save() # # expire other offers # for eoffer in Offer.objects(party=offer.initiator): # eoffer.expired = True # # send expired notification here # for eoffer in Offer.objects() # send notification here from notifications import send_notification send_notification(offer.party.full_name, g.user.email, 'offer-accepted', { 'FNAME': offer.party.first_name, 'PARTYNAME': '%s %s.' % (g.user.first_name, g.user.last_name[0]), 'VENUENAME': offer.venue.name, 'TIME': offer.time, 'ANSWERURL': get_home()}) return jsonify()
def main(): args = get_args() init_logging(args.log_level) clean_opts = helper.clean_args(args) logging.info(f'Options: {clean_opts}') notifications.init_notifications(args.telegram_bot_token, args.telegram_chat_id) notifications.send_notification(f'Starting to record with options: {clean_opts})') mic = gpiozero.InputDevice(args.port) q = collections.deque(maxlen=args.rolling_window_size) c = 0 while True: time.sleep(args.sleep_time) c = c + 1 q.append(mic.value) # Wait until rolling window is full if len(q) < args.rolling_window_size: continue # Only calculate average after "rolling_window_size" iterations to decrease load if c % args.rolling_window_size != 0: continue if helper.signal_detected(q, threshold=args.threshold): notifications.send_notification( f'Threshold was crossed! Rolling average: {helper.average(q)} (Threshold: {args.threshold})' ) logging.info(f'Signal detected: {helper.get_timestamp()}') q.clear() time.sleep(args.cool_down_in_s)
def push(filename): # Config: try: f = open(filename, 'r') except IOError: logging.error("Config File does not exist, please provide a config file.(please see config.example.json)") return try: config = json.load(f) except : logging.error("Config File is not formated correctly. (please see config.example.json)") return logging.debug("recieved Config: %s" % config) # create notification: message = config["notification"]["message"] users = get_users(config) # DEBUG: logging.info("notifications to push: %s" % str(len(users) )) # push to Users: sent = [] not_sent = [] for user in users: token = user["token"] #uuid = user["uuid"] url = create_url(config,token) push_success = send_notification(token,message,url) if push_success: sent.append(token) else: not_sent.append(token) logging.info("pushed successfuly : %s" % str(len(sent) )) if len(not_sent): logging.error("error sending to : {}".format(' '.join(map(str, not_sent))))
def publish(self): self.published = True self.save() send_notification(recipient = self.publisher.profile.user, verb = u'已经发布了', actor = self, target = self)
def _send_notification(self, verb, recipient = None, **kwargs): if recipient is None: recipient = self.publisher.profile.user return send_notification(recipient = recipient, verb = verb, actor = u'系统', target = self, **kwargs)