Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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'})
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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'})
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
def removeSendToAll(number):
    conn = db.createCon()
    dbquery = 'DELETE FROM `to_send` WHERE `number` = %s' % (number)
    conn.query(dbquery)
    conn.commit()
Ejemplo n.º 18
0
def getCursor(con = None):
	if con == None:
		con = db.createCon()
	return con.cursor()
Ejemplo n.º 19
0
def getCursor(con=None):
    if con == None:
        con = db.createCon()
    return con.cursor()
Ejemplo n.º 20
0
def removeSendToAll(number):
	conn = db.createCon()
	dbquery = 'DELETE FROM `to_send` WHERE `number` = %s' % (number)
	conn.query(dbquery)
	conn.commit()