Пример #1
0
 def test_show_available_products(self):
     """Test for show_available_products function from database.py"""
     client = MongoClient()
     db = client['database']
     product = db['product']
     add_data(product, 'products.csv')
     self.assertEqual(4, len(show_available_products(db)))
     test_result = show_available_products(db)
     self.assertTrue('9736' in test_result)
     self.assertTrue('6001' not in test_result)
     drop_all(db)
Пример #2
0
 def test_add_data(self):
     """Test for add_data function from database.py"""
     client = MongoClient()
     db = client['database']
     product = db['product']
     customer = db['customer']
     rentals = db['rentals']
     self.assertEqual(0, add_data(product, 'products.csv'))
     self.assertEqual(0, add_data(customer, 'customers.csv'))
     self.assertEqual(0, add_data(rentals, 'rentals.csv'))
     self.assertEqual(['customer', 'rentals', 'product'],
                      db.list_collection_names())
     drop_all(db)
Пример #3
0
 def test_show_rentals(self):
     """Test for show_rentals function from database.py"""
     client = MongoClient()
     db = client['database']
     customer = db['customer']
     rentals = db['rentals']
     add_data(customer, 'customers.csv')
     add_data(rentals, 'rentals.csv')
     test_result = show_rentals(db, '6921')
     self.assertTrue('AP987' in test_result)
     test_result2 = show_rentals(db, '2953')
     self.assertTrue('AP990' in test_result2)
     test_result3 = show_rentals(db, '0000')
     self.assertEqual(None, test_result3)
     drop_all(db)
Пример #4
0
 def add_action(self, message: telebot.types.Message, person_id):
     if isinstance(message.text, str):
         if message.text.lower() == 'все':
             self.bot.send_message(
                 message.from_user.id, 'Замечательно, все внесено в план! '
                 'Ты всегда можешь посмотреть свой список дел,'
                 ' просто написав мне \'меню\' и нажав на кнопку '
                 '\'Посмотреть план на день\'')
         else:
             database.add_data(person_id, 'plan', message.text)
             self.bot.send_message(message.from_user.id, "Что-то еще?")
             self.bot.register_next_step_handler(message, self.add_action)
     else:
         self.bot.send_message(message.from_user.id,
                               "Давай лучше текстом, хорошо?")
         self.bot.register_next_step_handler(message, self.add_action)
def googleSearch(words, matches, min_value, max_value, sleep_time):

    try:
        if matches:
            words = words[21:]
            query.append(words)
        else:
            query.append("You didn't say, 'Hey bot search for me' :(")
            query.append(words)
            res = "Tab opened with " + str(
                max_value) + " links, according settings Min : " + str(
                    min_value) + ", Max : " + str(
                        max_value) + ", Sleep time : " + str(sleep_time)
            links.append(res)
            links.append(" ")
        if words:
            for data in search(words,
                               tld="co.in",
                               num=min_value,
                               stop=max_value,
                               pause=sleep_time):
                links.append(data)
                webbrowser.open(data)
                date = str(
                    datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                db_res = database.add_data(date, words, data)
                if db_res == 1:
                    errors.append(" ")
                    errors.append(
                        "Voice search assistant could not connect with database."
                    )

            links.append(" ")
            links.append("Your search results are successfully completed.")
            links.append(" ")
            words = ""

    except:
        errors.append(
            "Voice search assistant could not open web browser for search results, try again."
        )
        errors.append(" ")
        errors.append("Turn ON, to search your queries.")
        errors.append(" ")

    print('Done from googleSearch')
Пример #6
0
    def menu():
        connection = database.connect()
        database.create_database(connection)

        while (user_input := input(menu_prompt)) != "7":
            if user_input == "1":
                app = input("Type the name of the app or website: ")
                user = input("Type the user name: ")
                pw_choice = input('''Please, choose one of these options
                1. Type my own password
                2. Use the 'Secure Password Generator 
                Your choice is: ''')
                if pw_choice == "1":
                    password = input("Type your password: "******"2":
                    PasswordGenerator.pw_lenght()
                    psswrd = input(
                        '''If you want to try a new password type "1".
    You can still write your own password or if you like the password, you can copy it and paste it here: '''
                    )
                    if psswrd != "1":
                        password = psswrd
                    else:
                        continue
                else:
                    print("Sorry, invalid input")

                database.add_data(connection, app, user, password)

            elif user_input == "2":
                data = database.get_all_data(connection)

                for info in data:
                    print(info)

            elif user_input == "3":
                app = input("Please, type the app you want to delete: ")

                database.delete_info(connection, app)

            elif user_input == "4":
                update = input("Please, type the app you want to update: ")
                new_app = input("The new name will be: ")
                new_user = input("The new user name will be: ")
                new_pw = input("The new password will be: ")

                database.modify_column(connection, new_app, new_user, new_pw,
                                       update)

            elif user_input == "5":
                username = input("Type the user name you are looking for: ")
                find_user = database.get_by_user(connection, username)

                for user in find_user:
                    print(user)

            elif user_input == "6":
                appname = input("Type the app you are looking for: ")
                find_app = database.get_by_app(connection, appname)

                for app in find_app:
                    print(app)

            else:
                print("Invalid input, please try again.")
Пример #7
0
    keys = temp_list.pop(0)
    temp_list = [{
        keys[i].lower(): dataConversions[i](thing[i])
        for i in range(len(keys))
    } for thing in temp_list]
    return temp_list


if __name__ == "__main__":
    import sys
    if not "-" in sys.argv:
        print("Need an option: try using -p or -p after the arguments")
        sys.exit(0)
    if "-p" in sys.argv:
        if "app" in sys.argv[1].lower():
            print(readApplicantCSV(sys.argv[2]))
        else:
            print(readDataCSV(sys.argv[2]))
    if "-l" in sys.argv:
        import database
        applicants = readApplicantCSV(sys.argv[2])
        data = readDataCSV(sys.argv[3])
        idDict = {}
        for napplicant in applicants:
            num = database.add_applicant(**applicants[napplicant])
            idDict[napplicant] = num
        for datum in data:
            datum["applicant"] = idDict[datum["applicantid"]]
            del datum["applicantid"]
            database.add_data(**datum)
Пример #8
0
 def new_lesson(self, message: telebot.types.Message):
     self.buffer_lesson[2] = message.text
     database.add_data(message.chat.id, 'timetable',
                       ' '.join(self.buffer_lesson))
     self.bot.send_message(message.chat.id,
                           'Готово! Вписал новое занятие в расписание:)')
Пример #9
0
def fonct():
    if request.method == 'POST':
        Protocol = request.form['Protocol']
        key = request.form['key']
        add_data(Protocol, key)
    return render_template('ex.html')
Пример #10
0
 def save_bookmark(self):
     add_data(self.restaurant, self.recipe, self.image)