コード例 #1
0
ファイル: httpRequests.py プロジェクト: iduque/UHCore
class RobotCommands(object):
    
    def __init__(self):
        self._dao = DataAccess()
    
    exposed = True

    def POST(self, *args, **kwargs):
        
        request = json.loads(cherrypy.request.body.read())
        
        # Send the robot to certain location
        if request.has_key('location'):
            object = self._dao.getLocationByName(request['location']);
            robot = Factory.getCurrentRobot();

            robot.setComponentState('tray', request['tray'])
            robot.setComponentState('base', [object['xCoord'], object['yCoord'], object['orientation']])

        # Send voice command to the robot (espeak software required)        
        elif request.has_key('speech'):

            if self._dao.getUserPreferences()[0]['voice'] == 1:
                import subprocess
                #subprocess.call(['C:\\Program Files (x86)\\eSpeak\\command_line\\espeak.exe', request['speech']]) #Windows
                subprocess.call(['espeak', request['speech']]); #Linux
        else:      
            raise cherrypy.HTTPError(400)      
コード例 #2
0
ファイル: httpRequests.py プロジェクト: iduque/UHCore
class UserData(object):
    
    def __init__(self):
        self._dao = DataAccess()
        
    exposed = True

    def GET(self, *args, **kwargs):
        
        if len(args) < 1:
            raise cherrypy.HTTPError(400)
        
        questionNo = args[0]
        if questionNo == 'preferences':
            value = self._dao.getUserPreferences()
        elif questionNo == 'persona':
            value = self._dao.getPersonaValues()
        elif questionNo == 'username': 
            value = self._dao.getActiveUserName()
        elif questionNo == 'experimentLocation':
            value = self._dao.getActiveExperimentLocation()
        
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps(value)
    
    def POST(self, *args, **kwargs):
        
        request = json.loads(cherrypy.request.body.read())

        if request.has_key('time'):
            time = datetime.datetime.now().strftime('%H:%M:%S') #strftime('%Y-%m-%d %H:%M:%S') 
            self._dao.setSessionControlTime(time)
        elif request.has_key('preferences'):
            for column, value in request.iteritems():
                if column != 'preferences':
                    print column + " " + value
                    self._dao.setUserPreferences(column, value)
        else:
            raise cherrypy.HTTPError(400)