def pickupSchedule(): current_ts = Utils.getCurrentTimestamp() date = current_ts.split(' ')[0] # Order Pickup order_list = [] cursor = mysql.connect().cursor() user_id_format_char = ",".join(["%s"] * len(Utils.getAdmins())) cursor.execute( """SELECT COUNT(*) FROM orders WHERE DATE(order_return) = %s AND order_id NOT IN (SELECT DISTINCT parent_id FROM orders) AND user_id NOT IN (""" + user_id_format_char + """) AND order_status >= 4""", tuple([date]) + tuple(Utils.getAdmins())) order_ids = cursor.fetchone() if order_ids[0] > 0: Utils.notifyAdmin(-1, "PICKUPS DUE TODAY!!") cursor.execute( """SELECT COUNT(*) FROM b2b_users WHERE DATE(timestamp) = %s""", (Utils.getDefaultReturnTimestamp(current_ts, -21).split(' ')[0], )) order_ids = cursor.fetchone() if order_ids[0] > 0: Utils.notifyAdmin(-1, "B2B PICKUPS DUE!!") return None
def sendMassNotification(self, notification_data, admin=0): if 'notification_id' in notification_data: notification_data['collapse_key'] = notification_data[ 'notification_id'] if admin: admins = ",".join([str(_) for _ in Utils.getAdmins()]) query_condition = " WHERE user_id in (" + admins + ")" else: query_condition = " UNION SELECT gcm_id FROM users_unregistered" cursor = mysql.connect().cursor() cursor.execute("""SELECT gcm_id FROM users""" + query_condition) all_gcm = cursor.fetchall() all_gcm_ids = [] for gcm in all_gcm: all_gcm_ids.append(gcm[0]) self.gcm.json_request(registration_ids=all_gcm_ids, data=notification_data)
def searchString(): response = {'status': 'False'} results = {} query = Utils.getParam(request.args, 'q') page = Utils.getParam(request.args, 'page', var_type='int', default=1) search_type = Utils.getParam(request.args, 'type', default='free') user_id = Utils.getParam(request.args, 'userId', 'int') flow = Utils.getParam(request.args, 'flow', default='borrow') gcm_id = Utils.getParam(request.args, 'gcm_id', default=None) uuid = Utils.getParam(request.args, 'distinct_id', default=None) ref = Utils.getParam(request.args, 'ref', default='mobile') if not query: return Utils.errorResponse(response, 'HTTP_STATUS_CODE_DATA_MISSING') if ref == 'web': return json.dumps(WebUtils.fetchSearchResults(query, search_type, page)) user_info = {'user_id': user_id, 'gcm_id': gcm_id, 'uuid': uuid} search = Search(query, user_info, flow) if search_type == 'free': results = search.basicSearch(page=page - 1) elif search_type == 'category': results = search.categorySearch(page=page - 1) elif search_type == 'collections': results = search.collectionsSearch(page=page - 1) elif search_type == 'isbn': results = search.isbnSearch(page=page - 1) elif search_type == 'auto': results = search.autoComplete() elif search_type == 'custom': results = search.customQuery() return results #log if user_id not in Utils.getAdmins(): Search.logSearch({_: request.args.get(_) for _ in request.args}, search_type) return jsonify(results) if flow != 'admin' else jsonp(results)