def GET(self): data = web.input() # ?cellno=0845678910&reply=64353264&replydate=2013-04-17%20203 web.header('Content-Type', 'text/plain') if not self._is_valid_request(data): raise web.badrequest('Invalid request') data.reply = data.reply.replace(' ', '') if not self._is_valid_text(data.reply): return try: message = self._parse_query(data).save() except Exception as exc: raise web.badrequest(exc.args[0]) reply_text = 'Thanks for your input! You sent %s @ %s' % (Product(message.product_code).fetch().name, Shop(message.shop_code).fetch().name) response = util._send_sms(message.customer_number, reply_text) return response.content
def send_notification(self, shop_code, product_code): affected_messages = Message().fetch_by(shop_code=shop_code, product_code=product_code) if affected_messages.count() == 0: raise web.seeother("/") product = Product(product_code).fetch() shop = Shop(shop_code).fetch() loyalty_code = self.generate_loyalty_code() # TODO: need to generate IN loop reply_text = '%s is back in stock @ %s. Your loyalty code is %s' % (product.name, shop.name, loyalty_code) response = util._send_sms([m['customer_number'] for m in affected_messages], reply_text ) if response is not None: response_list = json.loads(response.content)['results'] for r in response_list: if r['status'] == '0': affected_messages.collection.update({'notified': False, 'product_code': product_code, 'shop_code': shop_code , 'customer_number': r['destination']}, {'$set': {'notified': True}}) return response.content