def addSendToAll(number, text): conn = db.createCon() text = conn.escape_string(text.encode('UTF-8')) #UPSERT addquery = u"REPLACE INTO `to_send`(`number`, `text`) VALUES ('%s', '%s')".encode('UTF-8') %(number, text) conn.query(addquery) conn.commit()
def sent(): con = db.createCon() # Validate and Get POST data keys = request.form.keys() has_key = has_name = has_ids = False for key in keys: if key == 'key': has_key = True if key == 'name': has_name = True if key == 'ids': has_ids = True if not has_key or not has_name: return json.dump({'error': "NO, Input Error!"}) mobile_key = request.form['key'] mobile_name = request.form['name'] if not db.isMobileValid(con, mobile_name, mobile_key): con.close() return json.dump({'error': "NO! your name and/or key is not here!"}) if has_ids: success_ids = request.form['ids'] db.setSentTime(con, success_ids) con.close() return json.dumps({'success': 'success'}) else: con.close() return json.dumps({'error': 'NO! success'})
def phoneRang(who): sms_received_type = 'phone-rang' conn = db.createCon() comment_text = "form: %s" %(who) logquery = "INSERT INTO `logs`(`type`, `comment`) VALUES ('%s', '%s')" %(sms_received_type, comment_text) conn.query(logquery) closeCon(conn)
def rang(): con = db.createCon() json_data = json.loads(request.data) keys = json_data.keys() has_key = has_name = has_from = True for k in keys: if k == 'key': has_key = True if k == 'name': has_name = True if k == 'from': has_from = True if not has_key or not has_name or not has_from: con.close() return json.dumps({'error': "NO, Input Error!"}) mobile_key = json_data['key'] mobile_name = json_data['name'] mobile_from = json_data['from'] if not db.isMobileValid(con, mobile_name, mobile_key): con.close() return json.dump({'error': "NO! your name and/or key is not here!"}) status = db.handelRing(mobile_from) return status
def receivedMessage(who, text): sms_received_type = 'sms-received' conn = db.createCon() text = conn.escape_string(text.encode('UTF-8')) comment_text = u"form: %s, text: %s".encode('UTF-8') %(who, text) logquery = u"INSERT INTO `logs`(`type`, `comment`) VALUES ('%s', '%s')".encode('UTF-8') %(sms_received_type, comment_text) conn.query(logquery) closeCon(conn)
def phoneRang(who): sms_received_type = 'phone-rang' conn = db.createCon() comment_text = "form: %s" % (who) logquery = "INSERT INTO `logs`(`type`, `comment`) VALUES ('%s', '%s')" % ( sms_received_type, comment_text) conn.query(logquery) closeCon(conn)
def addSendToAll(number, text): conn = db.createCon() text = conn.escape_string(text.encode('UTF-8')) #UPSERT addquery = u"REPLACE INTO `to_send`(`number`, `text`) VALUES ('%s', '%s')".encode( 'UTF-8') % (number, text) conn.query(addquery) conn.commit()
def receivedMessage(who, text): sms_received_type = 'sms-received' conn = db.createCon() text = conn.escape_string(text.encode('UTF-8')) comment_text = u"form: %s, text: %s".encode('UTF-8') % (who, text) logquery = u"INSERT INTO `logs`(`type`, `comment`) VALUES ('%s', '%s')".encode( 'UTF-8') % (sms_received_type, comment_text) conn.query(logquery) closeCon(conn)
def hasPendingSendToAll(number): conn = db.createCon() dbquery = 'SELECT * FROM `to_send` WHERE `number` = "%s" LIMIT 1' % (number) conn.query(dbquery) r = conn.store_result() if r.num_rows() > 0: return True else: return False
def hasPendingSendToAll(number): conn = db.createCon() dbquery = 'SELECT * FROM `to_send` WHERE `number` = "%s" LIMIT 1' % ( number) conn.query(dbquery) r = conn.store_result() if r.num_rows() > 0: return True else: return False
def get(): arr = [] con = db.createCon() LIMIT = 3 # Default value for a # Validate and Get POST data keys = request.form.keys() has_key = has_name = has_limit = False for key in keys: if key == 'key': has_key = True if key == 'name': has_name = True if key == 'limit': has_limit = True if (not has_key) or (not has_name): return json.dump({'error': "NO, Input Error!"}) mobile_key = request.form['key'] mobile_name = request.form['name'] if has_limit: LIMIT = request.form['limit'] if not db.isMobileValid(con, mobile_name, mobile_key): con.close() return json.dump({'error': "NO! your name and/or key is not here!"}) # RETURN THE MESSAGES get_query = "SELECT * FROM transactions WHERE delivered_to_phone_at IS NULL LIMIT %d" % LIMIT con.query(get_query) r = con.store_result() for i in xrange(0, r.num_rows()): dic = {} row = r.fetch_row() (m_id, m_to, m_text, c_CA, c_DTPA, d_SA, s_DA) = row[0] # Add to array dic['id'] = m_id dic['to'] = m_to dic['text'] = m_text arr.append(dic) # Update Database update_query = "UPDATE transactions SET delivered_to_phone_at = now() WHERE id = %d" % m_id con.query(update_query) con.commit() dic = {} dic['messages'] = arr j = json.dumps(dic) con.close() print j return j
def get(): arr = [] con = db.createCon() LIMIT = 3 # Default value for a # Validate and Get POST data keys = request.form.keys() has_key = has_name = has_limit = False for key in keys: if key == 'key': has_key = True if key == 'name': has_name = True if key == 'limit': has_limit = True if (not has_key) or (not has_name): return json.dump({'error': "NO, Input Error!"}) mobile_key = request.form['key'] mobile_name = request.form['name'] if has_limit: LIMIT = request.form['limit'] if not db.isMobileValid(con, mobile_name, mobile_key): con.close() return json.dump({'error': "NO! your name and/or key is not here!"}) # RETURN THE MESSAGES get_query = "SELECT * FROM transactions WHERE delivered_to_phone_at IS NULL LIMIT %d" % LIMIT con.query(get_query) r = con.store_result() for i in xrange(0,r.num_rows()): dic = {} row = r.fetch_row() (m_id, m_to, m_text, c_CA, c_DTPA, d_SA, s_DA) = row[0] # Add to array dic['id'] = m_id dic['to'] = m_to dic['text'] = m_text arr.append(dic) # Update Database update_query = "UPDATE transactions SET delivered_to_phone_at = now() WHERE id = %d" % m_id con.query(update_query) con.commit() dic = {} dic['messages'] = arr j = json.dumps(dic) con.close() print j return j
def getSendToAll(number): conn = db.createCon() dbquery = 'SELECT * FROM `to_send` WHERE `number` = "%s" LIMIT 1' % (number) conn.query(dbquery) r = conn.store_result() conn.commit() if r.num_rows() > 0: row = r.fetch_row() return row[0][1] else: return False
def getSendToAll(number): conn = db.createCon() dbquery = 'SELECT * FROM `to_send` WHERE `number` = "%s" LIMIT 1' % ( number) conn.query(dbquery) r = conn.store_result() conn.commit() if r.num_rows() > 0: row = r.fetch_row() return row[0][1] else: return False
def removeSendToAll(number): conn = db.createCon() dbquery = 'DELETE FROM `to_send` WHERE `number` = %s' % (number) conn.query(dbquery) conn.commit()
def getCursor(con = None): if con == None: con = db.createCon() return con.cursor()
def getCursor(con=None): if con == None: con = db.createCon() return con.cursor()