Exemple #1
0
	def handle_rooms(self, url):
	
		obj = None
		rooms = core.rooms.Rooms(self.key)

		if url == "create":

			lat = 0.0
			lng = 0.0
			rsize = 5

			try:
				rsize = int(self.get_argument("size"))
				lat = float(self.get_argument("lat"))
				lng = float(self.get_argument("long"))
			except:
				return obj

			room   =  {"name"		 : str(self.get_argument("name")),
					   "dsc" 		 : str(self.get_argument("dsc")),
					   "address" 	 : str(self.get_argument("address")),
					   "status" 	 : "",
					   "size"        : rsize,
					   "type"        : rooms.room_type_place,
					   "security"    : {"type": rooms.security_level_open, "password": ""},
					   "locname"	 : "",
					   "loc" 		 : [lat, lng],
					   "event" 		 : {"start": 0, "end": 0},
					   "ratings" 	 : {"rating1" : 0, "rating2" : 0},
					   "tickets"	 : {"message" : "", "url": "", "price": ""},
					   "conversation": None}


			oid = rooms.create(room)
			obj = {"result" : "success", "objid" : str(oid)}

			if obj is not None:
				rooms.strip_secure_details(obj)
				
		elif url == "get":
			cuid = login.get_user_fullid(self.key)
			oc = rooms.get(self.get_argument("lat", "0"), self.get_argument("long", "0"), self.get_argument("rad", "100"), None, None)
			
			if oc is None:
				obj = {"result" : "error", "message" : "No rooms around."}
				return 0
			
			obj = []
			for o in oc:
				rooms.strip_secure_details(o)
				rooms.format_room(o)
				o["subscribed"] = rooms.is_subscribed(o, cuid)
				o["intheroom"] = rooms.is_intheroom(o, cuid)
				

				obj.append(o)


		elif url == "get_info":
			cuid = login.get_user_fullid(self.key)

			o = rooms.get_info(self.get_argument("id", "0"))
			
			if o is None:
				obj = {"result" : "error", "message" : "No rooms around."}
				return obj
			
			rooms.strip_secure_details(o)
			rooms.format_room(o)
			o["subscribed"] = rooms.is_subscribed(o, cuid)
			o["intheroom"] = rooms.is_intheroom(o, cuid)
			obj = o


		elif url == "enter":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.enter(id)
			if oc == 1:
				obj = {"result" : "success"}


		elif url == "leave":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.leave(id)
			if oc == 1:
				obj = {"result" : "success"}


		elif url == "subscribe":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.subscribe(id)
			if oc == 1:
				obj = {"result" : "success"}


		elif url == "unsubscribe":
			id = self.get_argument("id", "0")
			
			if id == "0":
				return 0

			oc = rooms.unsubscribe(id)
			if oc == 1:
				obj = {"result" : "success"}

		elif url == "get_conversation":
			id    = str(self.get_argument("id", "0"))
			pid   = str(self.get_argument("pid", "0"))
			skip  = str(self.get_argument("skip", "0"))
			count = str(self.get_argument("count", "7"))
			noteskip  = str(self.get_argument("noteskip", "0"))
			notecount = str(self.get_argument("notecount", "5"))
			
			obj = {"result" : "error"}
			
			if id == "0":
				return obj

			try:
				skip = int(skip)
			except:
				skip = 0

			try:
				count = int(count)
			except:
				count = 1

			try:
				noteskip = int(noteskip)
			except:
				noteskip = 0

			try:
				notecount = int(notecount)
			except:
				notecount = 5

			oc = rooms.get_conversation(id)
			if oc is not None:
				conversations = core.conversations.Conversations(self.key)
				obj = conversations.get(conversations.get_default, oc, pid, skip, count, noteskip, notecount)


		return obj
Exemple #2
0
def main(args):
	print "started initialization"
		
	db.connect()
	people = core.people.People(0)
	rooms = core.rooms.Rooms(0)

	if db.roadhouse is not None:
		
		"""
		John Doe
		Jane Roe
		石戸谷 貞子
		
		"""
		
		print "db found"

		db.roadhouse.secure.remove()

		db.roadhouse.config.update({}, {"$set" : {"last_userid" : 0}}, True)
		db.roadhouse.people.remove()
		
		people.create({"fname" : "John",
					   "lname" : "Smith",
					   "username" : "johnsmith",
					   "email" : "*****@*****.**",
					   "rating" : {"rating1" : 0, "rating2" : 0},
					   "password" : "123",
					   "location" : {"name" : "Unknown Location", "type" : 0},
					   "coordinates" : [0, 0],
					   "description" : "A man of word",
					   "status" : "Good morning..."})
					   
		people.create({"fname" : "Mary",
					   "lname" : "Jane",
					   "username" : "maryjane",
					   "email" : "*****@*****.**",
					   "rating" : {"rating1" : 0, "rating2" : 0},
					   "password" : "123",
					   "location" : {"name" : "Unknown Location", "type" : 0},
					   "coordinates" : [0, 0],
					   "description" : "Hey!",
					   "status" : "Drawing some stuff."})
					   
		people.create({"fname" : "石戸谷",
					   "lname" : "貞子",
					   "username" : "sadako",
					   "email" : "*****@*****.**",
					   "rating" : {"rating1" : 0, "rating2" : 0},
					   "password" : "123",
					   "location" : {"name" : "Unknown Location", "type" : 0},
					   "coordinates" : [0, 0],
					   "description" : "Blah",
					   "status" : "Growing plants here..."})
					   
		db.roadhouse.rooms.remove()

		rooms.create({"name"		 : "Mayfield Park",
					   "dsc" 		 : "Love, peace, music",
					   "address" 	 : "7th street, Elf Town",
					   "status" 	 : "",
					   "size"        : 10,
					   "type"        : rooms.room_type_place,
					   "security"    : {"type": rooms.security_level_open, "password": ""},
					   "locname"	 : "",
					   "loc" 		 : [1.0, 1.0],
					   "event" 		 : {"start": 0, "end": 0},
					   "ratings" 	 : {"rating1" : 0, "rating2" : 0},
					   "tickets"	 : {"message" : "", "url": "", "price": ""},
					   "conversation": None})

		rooms.create({"name"		 : "Coffee Shop",
					   "dsc" 		 : "Jim's Coffee Spot",
					   "address" 	 : "22/1, Elf Town",
					   "status" 	 : "",
					   "size"        : 5,
					   "type"        : rooms.room_type_place,
					   "security"    : {"type": rooms.security_level_open, "password": ""},
					   "locname"	 : "",
					   "loc" 		 : [2.0, 1.0],
					   "event" 		 : {"start": 0, "end": 0},
					   "ratings" 	 : {"rating1" : 0, "rating2" : 0},
					   "tickets"	 : {"message" : "", "url": "", "price": ""},
					   "conversation": None})

		rooms.create({"name"		 : "College of Design and Arts",
					   "dsc" 		 : "Welcome to the Elf Town College of Art",
					   "address" 	 : "12/A, Elf Town",
					   "status" 	 : "",
					   "size"        : 20,
					   "type"        : rooms.room_type_place,
					   "security"    : {"type": rooms.security_level_open, "password": ""},
					   "locname"	 : "",
					   "loc" 		 : [1.0, 1.0],
					   "event" 		 : {"start": 0, "end": 0},
					   "ratings" 	 : {"rating1" : 0, "rating2" : 0},
					   "tickets"	 : {"message" : "", "url": "", "price": ""},
					   "conversation": None})
	else:
		print('Ouch!')