Esempio n. 1
0
def delete_topics(id):
    if not id:
	response.append({'response':'No TOPIC ID Recieved','responseCode':'400'})
        abort(400, response) 
    results = db.topics.remove( { '_id': id} )    
    theBody = json.dumps({'Status': "Success"})
    return bottle.HTTPResponse(status=200, body=theBody) 
Esempio n. 2
0
def get_lastupdated():
	query = "SELECT max(modified) FROM projects"
	db = connectdb()
	cursor = db.cursor() 
	cursor.execute(query)
	result = cursor.fetchall()
	response = []
	first = result[0]
	time = unix_time(first[0])
	response.append(time)
	cursor.close()
	db.close()
	return {'last_updated': response}		
Esempio n. 3
0
def put_topics(id):
    data = request.body.readline()
    response=[]
    if not data:
	response.append({'response':'No DATA Recieved','responseCode':'400'})
        abort(400, response)        
    entity = json.loads(data)
    if not entity.has_key('author'):
	response.append({'response':'No author specified','responseCode':'400'})
        abort(400, response)
    if not entity.has_key('comment'):
	response.append({'response':'No COMMENT specified','responseCode':'400'})
        abort(400, response)       
    results = db['topics'].find( { '_id': id})   
    if not results:
	response.append({'response':'No Topic Found with id %s' % id,'responseCode':'400'})        
        abort(400, response)
    commentsBuild = []
    commentsBuild.append({'author': entity["author"], 'comment': entity["comment"]})                
        
    for result in results:
        if result.has_key('comments'):
            for commentChild in result["comments"]:
		commentsBuild.append({'author': commentChild["author"], 'comment': commentChild["comment"]})
        d = {'_id':id, 'desc':result["desc"], 'topicName': result["topicName"],'author': result["author"],
         'comments': commentsBuild}      
    	
    	try:
        	db['topics'].save(d)
        	theBody = json.dumps({'Status': "Success",'comments':commentsBuild})
       		return bottle.HTTPResponse(status=200, body=theBody) 
    	except ValidationError as ve:
        	abort(400, str(ve))
Esempio n. 4
0
def get(mongodb, collection, slug, field={'key': 'slug'}):
    base()
    if slug:
        data = mongodb[collection].find_one({field['key']: slug})
        if data:
            data.pop('_id', None)
        else:
            data = {}
        return json.dumps(data, default=parse_dumps)
    else:
        data = mongodb[collection].find()
        response = []
        for d in data:
            d.pop('_id', None)
            response.append(d)
    return json.dumps(response, default=parse_dumps)
Esempio n. 5
0
def get(mongodb, collection, slug, field={'key': 'slug'}):
    base()
    if slug:
        data = mongodb[collection].find_one({field['key']: slug})
        if data:
            data.pop('_id', None)
        else:
            data = {}
        return json.dumps(data, default=parse_dumps)
    else:
        data = mongodb[collection].find()
        response = []
        for d in data:
            d.pop('_id', None)
            response.append(d)
    return json.dumps(response, default=parse_dumps)
Esempio n. 6
0
def run_query(query):
	db = connectdb()
	cursor = db.cursor() 
	cursor.execute(query)
	result = cursor.fetchall()
	response = []
	for row in result:
		item = {}
		for i in range(len(fields)):
			r = row[i]
			if type(r) == str:
				r = r.encode('utf-8')
			item[fields[i]] = r
		response.append(item)
	cursor.close()
	db.close()
	return {'projects': response}
def trendingChannels():
    twitv = TwiTv()
    rank = twitv.channelRank()
    response = []
    i = 0
    while i < len(rank):
        twits = rank[i][0]
        idChannel = rank[i][1]
        channelName = rank[i][2]
        channelNumber = str(rank[i][3])
        channelImage = rank[i][4]
        response.append(
            {
                "twits": twits,
                "idChannel": idChannel,
                "channelName": channelName,
                "channelNumber": channelNumber,
                "channelImage": channelImage,
            }
        )
        i += 1
    return json.dumps({"response": response})
Esempio n. 8
0
def put_topic():
    data = request.body.readline()
    response=[]
    if not data:
	response.append({'response':'No DATA Recieved','responseCode':'400'})
        abort(400, response)
    entity = json.loads(data)
    if not entity.has_key('topicName'):
        response.append({'response':'NO TOPIC NAME PROVIDED','responseCode':'400'})
        abort(400, response)
    if not entity.has_key('author'):
        response.append({'response':'NO AUTHOR NAME PROVIDED','responseCode':'400'})
        abort(400, response)
    if not entity.has_key('desc'):
        entity.desc=""   
    topicId = entity["topicName"]+"_"+entity["author"]
    d = {'_id':topicId, 'desc':entity["desc"], 'topicName': entity["topicName"],'author': entity["author"]}       
       
    try:
	db['topics'].save(d)
	theBody = json.dumps({'topicId': topicId})
        return bottle.HTTPResponse(status=200, body=theBody)       
    except ValidationError as ve:
        abort(400, str(ve))