コード例 #1
0
ファイル: test_database.py プロジェクト: rphilander/proteus
 def test_shorter_row(self):
     db = DB()
     line = ['America',
             '3000',
             'Super Something',
             '1',
             '2',
             '3',
             '6']
     target = (None,
               None,
               u'America',
               3000,
               u'Super Something',
               1,
               2,
               3,
               6)
     input = '\t'.join(line)
     db.load([input])
     self.assertEqual(db.query('select * from medals')[1], target)
コード例 #2
0
ファイル: test_database.py プロジェクト: rphilander/proteus
 def test_full_row(self):
     db = DB()
     line = ['The Man',
             '99',
             'America',
             '3000',
             'Super Something',
             '1',
             '2',
             '3',
             '6']
     target = (u'The Man',
               99,
               u'America',
               3000,
               u'Super Something',
               1,
               2,
               3,
               6)
     input = '\t'.join(line)
     db.load([input])
     self.assertEqual(db.query('select * from medals')[1], target)
コード例 #3
0
ファイル: server.py プロジェクト: rphilander/proteus
from bottle import route, run
from bottle import request
from bottle import static_file
from bottle import template
from bottle import view

from core import AtomIndex, interpret
from database import DB
import grammar
import rows2atoms

# initialize stuff
db = DB()
with open('raw_data/filtered.txt') as raw_data:
    db.load(raw_data)
atom_index = AtomIndex('web-ui')
for atom in rows2atoms.transform(db.query('select * from medals')):
    try:
        atom_index.write(atom)
    except UnicodeEncodeError:
        pass
map(atom_index.write, grammar.get_atoms())


@route('/')
def hello():
    return static_file('html/index.html', root='static')

@route('/static/<filepath:path>')
def server_static(filepath):
コード例 #4
0
ファイル: serve.py プロジェクト: abrobbins90/groceries
class SocketHandler (WebSocketHandler):
	""" The WebSocket protocol is still in development. This module currently implements
	the hixie-76 and hybi-10 versions of the protocol. See this browser	compatibility
	table on Wikipedia: http://en.wikipedia.org/wiki/WebSockets#Browser_support """


	def open(self):
		print 'websocket opened!'
		# Create an instance of the recipe database to handle all requests
		self.db = DB()

	def on_message(self, message):
		# Convert things to be more friendly.  Check for good input.
		assert type(message) in [str, unicode]
		print 'got message: {0}'.format(message)
		message_dict = json.loads(message)
		assert type(message_dict) == dict
		# Check to ensure a command is received
		if "command" not in message_dict:
			raise KeyError("Key 'command' is missing. Way to suck...")
		command	= message_dict["command"]
		# Grab data and token if they are passed
		if "data" in message_dict:
			data = message_dict["data"]
		else:
			data = "" # Avoid an error later on if data is expected
		if "token" in message_dict:
			token = message_dict["token"]
			respond = True
		else:
			respond = False
		response = {} # Initialize as dictionary

		### Check the command received and proceed accordingly
		# user commands
		if command == "login":
			# Query the database for this user. If successful, assign username and return user info
			success = self.db.user_login(data)
			if success:
				print 'Successful login: '******'Loaded all data to user'
			else:
				print 'Unsuccessful login attempt from: ' + data['username']
				response["status"] = False

		elif command == "logout":
			# If logged in, log out
			if self.db.is_logged_in():
				self.db.logout()
				response["status"] = True
			else:
				response["status"] = False

		elif command == "user-query":
			# Check if username already exists
			exist = self.db.user_query(data)
			response["status"] = exist

		elif command == "add-user":
			# Add a new user
			success = self.db.add_user(data)
			if success:
				print 'Added user: '******'username']
			else:
				print 'Failed to add user: '******'username']
			# Send response to user query
			response["status"] = success
		elif command == "delete-user":
			#Delete a user's account
			success = self.db.delete_user(data)
			if success:
				print 'Deleted user: '******'username']
			else:
				print 'Failed to delete user: '******'username']
			# Send response to user query
			response["status"] = success

		# Node operations
		elif command == "add-node":
			success = self.db.add_node(data)
			if success:
				print 'added node'
			else:
				print 'failed to add node'

		elif command == "remove-node":
			success = self.db.remove_node(data)
			if success:
				print 'removed node'
			else:
				print 'failed to remove node'

		elif command == "add-edge":
			success = self.db.add_edge(data)
			if success:
				print 'added edge'
			else:
				print 'failed to add edge'

		elif command == "remove-edge":
			success = self.db.remove_edge(data)
			if success:
				print 'removed edge'
			else:
				print 'failed to remove edge'


		elif command == "update-node-info":
			success = self.db.update_node_info(data)
			if success:
				print 'updated node info'
			else:
				print 'failed to update node info'

		elif command == "update-data":
			# Request data is updated
			response["status"] = True
			response["data"] = self.db.load()
			print 'Sent full data back to user'

		# If a response is expected, send onem even if it's empty
		if respond:
			response["token"] = token
			self.send_message('response', response)

	def send_message(self, command, data):
		self.write_message({
			'command': command,
			'data': data,
		})

	def on_close(self):
		print 'websocket closed'