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 returnDateExtensionReminder(): current_timestamp = Utils.getCurrentTimestamp() return_date = Utils.getDefaultReturnTimestamp(current_timestamp, 3) cursor = mysql.connect().cursor() cursor.execute("""SELECT order_id, user_id FROM orders WHERE DATE(order_return) = DATE('%s') AND order_status >=4 AND order_id NOT IN (SELECT DISTINCT parent_id FROM orders) AND bought = 0 """ % (return_date)) num_items = cursor.rowcount for num in range(num_items): query_data = Utils.fetchOneAssoc(cursor) user = User(query_data['user_id']) print 'order_id:', query_data['order_id'] notification_data = { "notification_id": 3, "entity_id": query_data['order_id'], "order_type": "borrow", "title": "3 Days Left to Return the Book", "message": "Not finised yet? Extend the reading period.", "expanded_text": "You can extend the reading period by going to the order's page in \"My Orders\".", "order_type": "borrow" } Notifications(user.gcm_id).sendNotification(notification_data) #if int(query_data['user_id']) in Utils.getAdmins(): upsellEmail(query_data['order_id'])
def pickupTimeslot(): current_timestamp = Utils.getCurrentTimestamp() return_date = Utils.getDefaultReturnTimestamp(current_timestamp, 1) cursor = mysql.connect().cursor() cursor.execute("""SELECT order_id, user_id, pickup_slot FROM orders WHERE DATE(order_return) = DATE('%s') AND order_status >=4 AND order_id NOT IN (SELECT DISTINCT parent_id FROM orders) """ % (return_date)) num_items = cursor.rowcount for num in range(num_items): query_data = Utils.fetchOneAssoc(cursor) user = User(query_data['user_id']) ts = Order.getTimeSlot(query_data['pickup_slot']) ts = Utils.cleanTimeSlot(ts) notification_data = { "notification_id": 3, "entity_id": query_data['order_id'], "order_type": "borrow", "title": "Return Date Tomorrow", "message": "Would you like to extend your reading period?", "expanded_text": "You can extend the reading period by going to the order's page in \"My Orders\". We'd contact you shortly to confirm your current pickup time: %s" % ts, "order_type": "borrow" } Notifications(user.gcm_id).sendNotification(notification_data)