def push(): msg = request.args.get('msg') d ={} d['msg'] = msg d['type'] = 'push' Push.message(json.dumps(d),channels=[""]) return jsonify(data="success")
def garage_opened(all_sensors, all_rules): garage = True for sensor in all_sensors: if sensor.name == 'Garage': sensor.open = True sensor.save() for rule in all_rules: if rule.rule_id == 1 and rule.is_enabled: msg = 'You left a window open! Close it to avoid a security risk before leaving.' Push.message(msg, channels=["Notifications"]) history_item = History(Text=msg) history_item.save() message = sendgrid.Mail(to='*****@*****.**', subject='Allstate Hub Notification', html='', text=msg, from_email='*****@*****.**') status, mersg = sg.send(message) elif rule.rule_id == 3 and rule.is_enabled: # napi = nest.Nest(username, password) # for device in napi.devices: # prev_nest_mode_garage = device.mode # device.mode = 'off' print 'Nest mode set to off and previous state stored.' elif rule.rule_id == 4 and rule.is_enabled: msg = 'Make sure the alarm system is enabled!' Push.message(msg, channels=["Notifications"]) history_item = History(Text=msg) history_item.save() message = sendgrid.Mail(to='*****@*****.**', subject='Allstate Hub Notification', html='', text=msg, from_email='*****@*****.**') status, mersg = sg.send(message)
def notify(request): restaurant = request.GET.get('restaurant') msg = "True" d = {} d['alert'] = msg d['type'] = 'push' Push.message("Your order from "+ str(restaurant) + " is complete.", channels=[""]) return HttpResponse(json.dumps({'status': True}))
def _send_push_notification(message, channels, **kwargs): try: if isinstance(message, basestring): Push.message(message, channels=channels, **kwargs) elif isinstance(message, dict): Push.alert(message, channels=channels, **kwargs) except Exception as e: logger.error(u'Failed to send push ({0}, {1}, {2}): {3}'.format( message, channels, kwargs, e)) else: logger.info(u'Successfully sent push ({0}, {1}, {2})'.format( message, channels, kwargs))
def smoke_on(all_sensors, all_rules): smoke = True GPIO.output(4, 1) for sensor in all_sensors: if sensor.name == 'Smoke': sensor.open = True sensor.save() for rule in all_rules: if rule.rule_id == 6 and rule.is_enabled: msg = 'Smoke alarm was triggered!' Push.message(msg, channels=["Notifications"]) history_item = History(Text=msg) history_item.save() message = sendgrid.Mail(to='*****@*****.**', subject='Allstate Hub Notification', html='', text=msg, from_email='*****@*****.**') status, mersg = sg.send(message)
def handleDifference(before, current, typeR="daily"): db = connect2DB() if before != None and current != None: print "Before " + before[0]["date"].ctime() print "Current " + current[0]["date"].ctime() if before[0]["date"].ctime() != current[0]["date"].ctime(): for b in before: for c in current: if b["commodity"] == c["commodity"]: if typeR == "daily": if abs(b["price"] - c["price"]) > MIN_DIFF: print "price for ", b["commodity"], " changed" # Add new record to the general dataset # updateGeneralDataSet(c, b, typeR) # Send Push notification of change record change = "increased" if b["price"] >= c["price"]: change = "decreased" message = ( c["commodity"] + " has " + change + " to $" + str(c["price"]) + " per " + c["unit"] ) name = b["commodity"].replace(" ", "") idx = name.find("(") Push.message(message, channels=[name[0:idx]]) else: print "price for ", b["commodity"], " remained the same" pred = predict.run(c["commodity"]) if pred != -1: newRec = {"name": c["commodity"], "price": pred} db.predictions.insert(newRec) # breaktypeR if typeR == "daily": fetcher.storeMostRecentDaily(db, current) fetcher.storeDaily(db, current) if typeR == "monthly": fetcher.storeMostRecentMonthly(db, current) fetcher.storeMonthly(db, current) else: print "no new record found" else: print "Doesn't exist"
def upload(): title = request.form['title'] user_location = request.form['user_location'] user_email = request.form['user_email'] user_name = request.form['user_name'] user_phone = request.form['user_phone'] item_image = request.files['item_image'] item_image.save(os.path.join(app.config['UPLOAD_FOLDER']+"/tmp", item_image.filename)) img_url = upload_imgur(item_image) #img_url='' #process = multiprocessing.Process(target=upload_imgur,args=(item_image,img_url)) confidence = imageMatch(os.path.join(app.config['UPLOAD_FOLDER']+"/tmp", item_image.filename), os.path.join(app.config['UPLOAD_FOLDER'], "puma.png")) #pushTwitter(os.path.join(app.config['UPLOAD_FOLDER']+"/tmp", item_image.filename),'hi') D = DB() D.add_item(title, img_url,user_location,user_email,user_name) Push.message(confidence, channels=[""]) resp = jsonify(data=str(confidence['confidence'])) resp.status_code = 200 return resp
def testCanMessage(self): Push.message("Giants beat the Mets.", channels=["Giants", "Mets"]) Push.message("Willie Hayes injured by own pop fly.", channels=["Giants"], where={"injuryReports": True}) Push.message("Giants scored against the A's! It's now 2-2.", channels=["Giants"], where={"scores": True})
def garage_opened(all_sensors, all_rules): garage = True for sensor in all_sensors: if sensor.name == 'Garage': sensor.open = True sensor.save() for rule in all_rules: if rule.rule_id == 1 and rule.is_enabled: message = 'You left a window open! Close it to avoid a security risk before leaving.' Push.message(message, channels=["Notifications"]) history_item = History(Text=message) history_item.save() elif rule.rule_id == 3 and rule.is_enabled: # napi = nest.Nest(username, password) # for device in napi.devices: # prev_nest_mode_garage = device.mode # device.mode = 'off' print 'Nest mode set to off and previous state stored.' elif rule.rule_id == 4 and rule.is_enabled: message = 'Make sure the alarm system is enabled!' Push.message(message, channels=["Notifications"]) history_item = History(Text=message) history_item.save()
from parse_rest.installation import Push from parse_rest.connection import register from settings_local import APPLICATION_ID, REST_API_KEY, MASTER_KEY register(APPLICATION_ID, REST_API_KEY) Push.message("hi", channels=["Notifications"]) print 'Done'
def push(self): message = "Your next Mystery Box is ready to be opened!" ParsePush.message(message, channels=[""])