Esempio n. 1
0
def get_news_feeds():
    URL = 'http://newsapi.org/v2/top-headlines?country=in&apiKey=01ca42aa1b41426185867f49a1dfc499'
    response = requests.get(URL).json()
    if response['status'] == 'ok':
        read_news_feeds(response)
    else:
        speak(
            'sir there is some problem in fetching news feed please try after some time'
        )
def greet():
    global user_name
    hour = int(dt.now().hour)

    if user_name == '':
        user_name = 'sir'

    if hour>0 and hour<12:
        day_span = 'Morning'
    elif hour>=12 and hour<17:
        day_span = 'Afternoon'
    elif hour>=17 and hour<20:
        day_span = 'Evening'
    else:
        day_span = 'Night'
    speak(f'Good {day_span} {user_name} how can I help you')
Esempio n. 3
0
def verify_user(password):

    global user_name
    if password == '':
        take_user_name('sir you did not enter the password tell me your name')
        mycursor.execute(
            f'SELECT admin FROM users WHERE name = \"{user_name}\"')
        result = mycursor.fetchone()
        if result and 'Yes' in result:
            speak('you are logged in as a super user welcome')
            return '200'
        else:
            speak('sir you are not a super user so you cant use this service')
            return '405'
    else:
        print('verifying ...')
        speak('please wait a momment we are connecting you')
        mycursor.execute('SELECT * FROM users LIMIT 1')
        result = mycursor.fetchall()
        if result:
            verify_query = f'SELECT * FROM users WHERE name=\"{user_name}\" AND password=\"{password}\"'
            mycursor.execute(verify_query)
            result = mycursor.fetchone()
            if result:
                print('Enjoy The Service.')
                speak('connected successfully')
                return '200'
            else:
                print(
                    'No user found ,may be because of wrong user name or password'
                )
                speak(
                    'sir i think you are not a existing user or there is something wrong please try again after some time'
                )
                print('Try again later.')
                return '405'
def feedback(feedback):
    if (('good' in feedback) or ('great' in feedback) or ('nice' in feedback) or ('well done' in feedback) or ('i am happy' in feedback) or ('satisfied' in feedback) or ('impressed' in feedback)):
        speak('I am glad that you enjoyed my service sir and i am happy to help you')
        print('Thanks for your appreciation')
    elif (('ok' in feedback) or ('decent' in feedback)):
        speak('glad to help you sir and i will improve myself to provide more accuracy')
        print('Thanks for the valueable feedback')
    elif (('bad' in feedback) or ('worst' in feedback) or ('i am unhappy' in feedback) or ('poor' in feedback) or ('pathetic' in feedback)):
        speak('i am really sorry sir i will update myself to give better performance thanks for the feedback')
        print('Thanks for your valueable feedback,this will help me to improve further')
    return False
def tell_name():
    tell_name = f'My name is {name}'
    speak(tell_name)
    print(tell_name)
def tell_time():
    tell_time = ctime()
    print(tell_time)
    speak(f'current time is {tell_time}')
Esempio n. 7
0
def read_news_feeds(feeds):
    total_feeds = feeds['totalResults']
    if (total_feeds <= 0):
        speak('no news feed available')
    else:
        speak(
            f'there are total {total_feeds} news update how many feeds do you want to hear'
        )
        total = get_input_value(total_feeds)

        if total > total_feeds or total <= 0:
            speak('sorry but you have demanded non feasible amount')
        else:
            feeds = feeds['articles']
            for feed in range(total):
                title = feeds[feed]['title']
                description = feeds[feed]['description']
                content = feeds[feed]['content']
                speak(f'title of news number {feed+1} is {title}')
                speak(f'description of this news is {description}')
                speak(f'content of this news is {content}')
            speak('thats all sir hope you have enjoyed our service')
Esempio n. 8
0
def add_new_user(password, gender):

    global user_name
    if user_name == '':
        speak('sorry sir i am unable to grab your name please try again later')
        print('Empty name are not allowed')
        return '501'

    print('Joining ...')
    speak('please wait a momment we are joining you to our community')

    mycursor.execute('SELECT * FROM users LIMIT 1')
    result = mycursor.fetchone()
    if result:
        search_query = f'SELECT * FROM users WHERE name=\"{user_name}\"'
        mycursor.execute(search_query)
        result = mycursor.fetchone()

        if gender == 'Male':
            gen = 'sir'
        else:
            gen = 'mam'

        if result:
            print('username is already taken')
            speak(f'{gen} please choose a different username')
            return '405'

        search_query = f'SELECT * FROM users WHERE password=\"{password}\"'
        mycursor.execute(search_query)
        result = mycursor.fetchone()
        if result:
            print('password is already taken')
            speak(f'{gen} please choose a different password')
            return '405'

    add_query = f'INSERT INTO users (name,password,gender) VALUES (\"{user_name}\",\"{password}\",\"{gender[0]}\")'
    mycursor.execute(add_query)
    mydbs.commit()

    search_query = f'SELECT * FROM users WHERE name=\"{user_name}\" and password=\"{password}\"'
    mycursor.execute(search_query)
    result = mycursor.fetchone()

    if result:
        print(f'{mycursor.rowcount} new user added with name {user_name}')
        speak('you have successfully joined welcome to jarvis community')
        print('Thanks for joining')
        return '200'
    else:
        speak('there is something wrong with our backend we will fix it soon')
        speak('sorry for inconvenience sir')
        return '503'
Esempio n. 9
0
def initiate():
    speak(
        'sir before i start make sure you have a decent internet connection.')
    input('Hit Enter To Proceed')
    return authenticate()
Esempio n. 10
0
def authenticate():
    response = '405'
    global user_name
    command = take_command('sir are you a new user or existing one')

    if (('new' in command) and ('exiting' in command)):
        speak('sorry sir i am unable to sir serve you')

    elif 'existing' in command or 'not new' in command or 'now a new' in command or 'old' in command:
        speak('ok sir provide your username or password to use this service')
        take_user_name()
        if user_name.strip() != '':
            speak('Enter your Password')
            password = getpass(prompt='Password: '******'new' in command:
        speak(
            'ok sir welcome to my service i will need your details to use this service'
        )
        take_user_name()
        speak('tell me your gender')
        question = [
            List('gender', message="Your Gender: ", choices=['Male', 'Female'])
        ]
        answer = prompt(question)
        speak('set a password')
        password = getpass(prompt='Password: '******'gender'])

    return response