Ejemplo n.º 1
0
def load_model():
    from app import r
    if request.method == 'GET':
        rv = r.get('_model')
        return jsonify(model=rv, success=True), 200
    r.set('_model', reuest.data)
    return jsonify(success=True), 200
Ejemplo n.º 2
0
    def __getitem__(self, key):
        value = redis.get(self.__keytransform__(key))

        if value and self.__relationship__:
            # Create an object of the specified relationship
            return self.__relationship__(value.decode())

        return value
Ejemplo n.º 3
0
    def __getitem__(self, key):
        value = redis.get(self.__keytransform__(key))

        if value and self.__relationship__:
            # Create an object of the specified relationship
            return self.__relationship__(value.decode())

        return value
Ejemplo n.º 4
0
    def test_fetch_detail(self, score_listing):
        """Should get and store listing data."""
        result = fetch_detail(*self.listing_ids)

        for listing in listings():
            data = json.loads(r.get('listings.%s.data' % listing['listing_id']))

            assert data.pop('users') == 3
            assert data == listing
Ejemplo n.º 5
0
def index():
	if request.method == 'GET':
		return render_template('index.html')

	elif request.method == 'POST':
		# ipdb.set_trace()
		filename = request.form['filename']
		passwd = request.form['pass']
		# ipdb.set_trace()
		try:
			# check if file already exists
			# if doesnt exists then create a new file and enter details in redis
			if not r.exists(filename) or r.exists == None:
				r.hmset(filename,{request.remote_addr:filename})
				r.set(filename+'pass',passwd)
				a=soldier.run('touch app/files/' + filename)
				# start queue for sending data to clients 
				start_queue(filename)
			# if exists check for password
			else:
				if r.exists(filename+'pass'):
					if r.get(filename+'pass')!=passwd:
						return redirect('/')
		except:
			# exception will be if file is not present hence create the file
			r.hmset(filename,{request.remote_addr:filename})
			r.set(filename+'pass',passwd)
			a=soldier.run('touch app/files/' + filename)
			# start queue for sending data to clients 
			start_queue(filename)
			if r.get(filename+'pass')!=passwd:
				return redirect('/')

		# add filename to curr ip and vice versa in redis
		ip_file_map = r.hgetall(filename)
		ip_file_map[request.remote_addr] = filename
		r.hmset(filename,ip_file_map)
		r.set(request.remote_addr, filename)
		# store that user is logged in 
		session['logged_in'] = filename
		return redirect('/edit/' + filename)
Ejemplo n.º 6
0
 def get(self):
     """Return trending NFL players (already in JSON format)"""
     try:
         trending = json.loads(r.get('trending_store'))
     except:
         abort(400,
               response={
                   'status': 400,
                   'message': 'Trending players not found'
               })
     else:
         return utils.success(trending)
Ejemplo n.º 7
0
def index():
    rez = r.get("topstudent")
    ti = ''
    data = None
    top_grade = []
    if not rez:
        top_grade = list(Grade.objects().aggregate(*[{
            "$group": {
                "_id": {
                    "student": "$student",
                    "course": "$course"
                },
                "avggrade": {
                    "$avg": "$grade"
                }
            }
        }, {
            "$sort": {
                "avggrade": -1
            }
        }, {
            "$limit": 1
        }]))
        if top_grade:

            student_db = Student.objects.get(id=top_grade[0]["_id"]["student"])
            top_grade[0]["name"] = student_db.firstName
            top_grade[0]["lname"] = student_db.lastName

            course_db = Course.objects.get(id=top_grade[0]["_id"]["course"])
            s = json.dumps(top_grade[0], indent=4, sort_keys=True)
            r.set("topstudent", s)
            r.expire('topstudent', 30)
            rez = r.get("topstudent")

            ti = json.dumps(MongoEngineJSONEncoder(course_db),
                            indent=4,
                            sort_keys=True)
            data = json.loads(rez)
    return render_template("index.html", top_student=data, loaded=ti)
Ejemplo n.º 8
0
def new_client(conn, addr, clients_set):
	#first make client handshake to establish connection
	clients_set.add((conn,addr))
	handle_client_handshake(conn)
	filename = r.get(addr[0])
	print addr[0] + "testing" 
	print 'new client'
	while 1:
		ip = addr[0]
		print ip
		data_recv = conn.recv(4096)
		if not data_recv:
			break
		try:
			# data is sent by client in json
			# if it can be decoded push the data in queue
			data_from_client = decode_data(data_recv)
			data_from_client = json.loads(data_from_client)
			r.rpush(filename+'queue', data_from_client['value']+'$$$'+str(data_from_client['cursor']))
			r.rpush(filename+'enqueue', str(convert(data_from_client)))
			r.rpush(filename+'ip', ip)
		except Exception as e:
			print str(e)
Ejemplo n.º 9
0
def queue_data(filename):
	# this function is for each file (one fn per file when file is created)
	global clients_set
	while True:
		time.sleep(0.1)
		x = r.lpop(filename+'queue')
		if x:
			y = r.lpop(filename+'enqueue')
			z = r.lpop(filename+'ip')
			f=open('app/files/' + filename,'r')
			data = f.read()
			f.close()
			cursor = int(x.split('$$$')[1])
			val = int(x.split('$$$')[0])
			# get cursor position and character inserted
			if val!=46 and val != 8: # if backspace or delete is not pressed 
				data = data[:cursor-1] + chr(val) + data[cursor-1:]
			elif val == 8: # backspace
				data = data[:cursor-2] + data[cursor-1:]
			else: # delete
				data = data[:cursor] + data[cursor+1:]

			print 'write ' + data
			f=open('app/files/' + filename,'w')
			f.write(data);
			f.close()
			for con,addr in clients_set:
				print con,addr
				# send to all clients except the sender
				if r.get(addr[0]) == filename and addr[0]!=z:
					try:
						con.send(encode_data(y))
						print 'sent'
					except:
						print 'error'
						pass
Ejemplo n.º 10
0
def get_device_model_contribute_time(uid, mid):
    res = r.get("contribute-{}-{}".format(uid, mid))
    return res
Ejemplo n.º 11
0
def index():

    r.incr("hits")
    hits = int(r.get("hits"))

    return render_template("index.html", hits=hits)