Beispiel #1
0
def getTimer(command):
    if 'start' in command:
        timerStart = time.time()
        return ('Started')
    elif 'stop' in command:
        timerEnd = time.time()
        output(f'Elapsed time: {timerEnd - timerStart}')
        return (f'Elapsed time: {timerEnd - timerStart}')
        timerStart = 0
        timerEnd = 0
Beispiel #2
0
    def builder():
        with app.app_context():
            user = PoohUser.query.filter_by(name=curUser).first()

            if user:
                key = " ".join(command.split()[1:command.split().index("is")])
                val = " ".join(command.split()[command.split().index("is") +
                                               1:])

                userInfo = json.loads(user.additional_info)
                userInfo[key] = val
                user.additional_info = json.dumps(userInfo)
                db.session.commit()
                output('I\'ll remember that')
                return ('I\'ll remember that')
            else:
                output('No user')
Beispiel #3
0
    def switch():
        global curUser
        with app.app_context():
            lookupUser = PoohUser.query.filter_by(name=userName).first()

        if lookupUser:
            output(f'Hello, {userName}')
            curUser = userName
            return (f'Hello, {userName}')
        else:
            output(f'Welcome, {userName}')
            newUser = PoohUser(userName)
            curUser = userName
            with app.app_context():

                db.session.add(newUser)
                db.session.commit()
            return (f'Welcome, {userName}')
Beispiel #4
0
def delegator(app, task):
    # This is our exit point
    if 'quit' in task or 'goodbye' in task or 'exit' in task:
        output('\nHave a good rest of your day, Michael\n')

        return
    # This will put us into admin mode if the user enters the correct username and password
    elif 'admin' in task.lower():
        return adminStart(app)
    # This is a basic property that will get us the time
    elif 'time' in task.lower():
        return timeStart(task)
    # This is where we will play something on spotify
    elif 'play' in task.lower() or 'pause' in task.lower(
    ) or 'stop' in task.lower() or 'next' in task.lower(
    ) or 'prev' in task.lower():
        return spotifyStart(task)
    # This is where we will be able to manipulate tasks in todoist
    elif 'todoist' in task.lower() or 'task' in task.lower(
    ) or 'to do' in task.lower():
        return todoistStart(task)
    # This is where we enter the blackjack game
    elif 'blackjack' in task.lower():
        return play(app)
    # This is where we go to get pooh to tell us the weather
    elif 'weather' in task.lower() or 'temperature' in task.lower():
        return getWeather(task)
    # This is where we can do basic mathematical operations. This will be expanded later
    elif '+' in task or '-' in task or '/' in task or '*' in task:
        return mathStart(task)
    # This is how we switch users so that Pooh will know what information to access about each user
    elif 'this is' in task.lower():
        curUser = "".join(task.split()[2:])
        return switchUser(app, curUser)
    elif '?' in task:
        return profileAccessor(app, task)
    elif 'my' in task.lower() and 'is' in task.lower():
        return profileBuilder(app, task)
    else:
        output('Sorry, I can\'t do that.')
Beispiel #5
0
    def spotify():
        #if 'song' in task:
        if 'play' in task:
            requestType = 'track'
            path = 'tracks.items.[0].uri'
            wordArray = task.split()
            wordArray = wordArray[1:]

            # Doing some situational configuration
            if 'playlist' in task:
                requestType = 'playlist'
                wordArray.remove('playlist')
            elif 'album' in task or 'music by' in task:
                requestType = 'album'
                if 'album' in task:
                    wordArray.remove('album')
                else:
                    wordArray.remove('music')
                    wordArray.remove('by')

                path = 'albums.items.[0]'
            elif 'artist' in task:
                requestType = 'artist'
                wordArray.remove('artist')

            songTitle = " ".join(wordArray)

            # Making the request for the resource we need
            token = spotifyAuth()['access_token']
            headers = {'Authorization': f'Bearer {token}'}
            query = {'q': songTitle, 'type': requestType}
            r = requests.get('https://api.spotify.com/v1/search',
                             headers=headers,
                             params=query)
            call([
                'spotify', 'play', 'uri',
                json.loads(r.content)[f'{requestType}s']['items'][0]['uri']
            ],
                 stdout=open(os.devnull, 'wb'))

            output('Ok, here you go.')
        elif 'pause' in task or 'stop' in task:
            call(['spotify', 'pause'], stdout=open(os.devnull, 'wb'))
            output('Ok, stopped')
        elif 'next' in task:
            call(['spotify', 'next'], stdout=open(os.devnull, 'wb'))
            output('Can Do')
        elif 'prev' in task:
            call(['spotify', 'prev'], stdout=open(os.devnull, 'wb'))
            output('Whatever you say')
Beispiel #6
0
    def admin():
        username = input("Enter the admin username: "******"Enter the admin password: "******"ADMIN > ")
                if task == 'initialize db':
                    with app.app_context():
                        db.create_all()
                        output('I will store all of my memories here.')
                elif task == 'drop db':
                    call(['rm', 'pooh.db'], stdout=open(os.devnull, 'wb'))
                    output('Ok, I have deleted my memory.')
                elif 'exit' in task:
                    output('Exiting admin mode')
                    return
        else:
            output('Invalid Credentials')
Beispiel #7
0
    def accessor():
        global curUser
        with app.app_context():
            user = PoohUser.query.filter_by(name=curUser).first()
        if user:
            if 'my name' in command:
                output(f'Your name is {curUser}')
                return (f'Your name is {curUser}')
            else:
                userInfo = json.loads(user.additional_info)
                for key, val in userInfo.items():
                    if key in command:
                        output(f'Your {key} is {val}')
                        return (f'Your {key} is {val}')
                output('I don\'t know that yet. Please teach me.')
                return ('I don\'t know that yet. Please teach me.')

        else:
            output('No user')
            return ('No user')
Beispiel #8
0
def getCurTime():
    output(f'The current time is {str(datetime.datetime.now())}')
    return (f'The current time is {str(datetime.datetime.now())}')
Beispiel #9
0
def play(app):
    while True:
        handCards = copy.deepcopy(cards)

        # Dealing Pooh's cards
        poohHand = [getCard(handCards), getCard(handCards)]

        # Dealing the players cards
        playerHand = [getCard(handCards), getCard(handCards)]

        output(f'Pooh Hand: {poohHand[0]}, {poohHand[1]} ({sum(poohHand)})')
        output(
            f'Player Hand: {playerHand[0]}, {playerHand[1]} ({sum(playerHand)})'
        )

        # Asking the user if they would like to hit
        decision = ''
        while decision.lower() != 'stay':
            decision = input("Hit or Stay? ")
            if decision.lower() == 'hit':
                playerHand.append(getCard(handCards))
                output(f'Player Hand: {playerHand} ({sum(playerHand)})')
                if sum(playerHand) > 21:
                    output('You busted')
                    decision = 'stay'

        # Deciding if Pooh should hit
        # Check to see if we have encountered this hand before
        if sum(playerHand <= 21):
            with app.app_context():
                decision = ''
                while decision.lower() != 'stay':
                    playerHandString = toString(playerHand)
                    poohHandString = toString(poohHand)
                    previousData = PoohBlackJack.query.filter_by(
                        playerHand=playerHandString).filter_by(
                            poohHand=poohHandString).all()

                    # If we have encountered this hand, ensuring we have seen it at least 10 times
                    if len(previousData) > 10:
                        # if we have, then we want to use the historical statistics to make our decision
                        output('in here')
                    # If we haven't, we want to play the probablilities of the cards remaining in the deck
                    else:
                        odds = calculateOdds(poohHand, handCards)
                        if odds > .5:
                            poohHand.append(getCard(handCards))
                        else:
                            output(f'Pooh Hand: {poohHand} ({sum(poohHand)})')
                            decision = 'stay'

        game = PoohBlackJack(playerHandString, poohHandString)
        if sum(playerHand) > 21:
            output('Pooh wins')
        elif sum(poohHand) > 21:
            output('Player wins!')
        elif sum(poohHand) > sum(playerHand):
            output('Pooh wins!')
        elif sum(poohHand) < sum(playerHand):
            output('Player wins')
        else:
            output('Draw!')
        output('\n----------------------------------\n')
Beispiel #10
0
 def math():
     output('math')
Beispiel #11
0
def start():
	output('Hello, Mike.')
	while True:
		task = input("> ")
		thread = startThread(delegator(app, task))
		thread.join()