Exemplo n.º 1
0
    def test_import_data(self):
        """Test database.import_data"""

        success, fail = database.import_data(DATA_DIR, PRODUCTS, CUSTOMERS,
                                             RENTALS)

        # Order = products, customers, rentals
        names = ("Products", "Customers", "Rentals")
        n_prod = len(self.product_keys)
        n_cust = len(self.customer_keys)
        n_rent = len(self.rental_data)

        for correct, value, name in zip((n_prod, n_cust, n_rent), success,
                                        names):
            self.assertEqual(correct, value, name)

        self.assertEqual((0, 0, 0), fail, "Fail count")

        # Assert they were added to the database correctly
        with database.DBConnection() as db:
            self.assertEqual(len(self.rental_data),
                             db.rentals.count_documents({}), "Rental count")
            self.assertEqual(len(self.product_keys),
                             db.products.count_documents({}), "Prod count")
            self.assertEqual(len(self.customer_keys),
                             db.customers.count_documents({}), "Cust count")
Exemplo n.º 2
0
    def tearDown(self) -> None:
        """
        Remove database data.

        .. note::
            For some reason, the patch decorators on the class
            DO NOT get applied to ``setUp`` or ``tearDown``.
        """

        with database.DBConnection() as db:

            db.product.delete_many({})
            db.customers.delete_many({})
            db.rentals.delete_many({})

            for name in ('products', 'customers', 'rentals'):
                db.drop_collection(name)
# Orchestrate the whole foursquare monitoring system process from here
import json
import sys
# Add the main folder to the python library, so that we can import our database
sys.path.append('../../')
import database

############################################ Foursquare monitoring ##############################################
import foursquareAPI

foursquareAPI = foursquareAPI.FoursquareAPI("foursquareStats.json")

myDB = database.DBConnection()

possibleTourismValues = foursquareAPI.options['tourism'].split(',')

for tourismCat in possibleTourismValues:
    if tourismCat in foursquareAPI.categories:
        categoryID = foursquareAPI.categories[tourismCat]
        while True:
            response = foursquareAPI.getVenuesPerCategory(categoryID)
            try:
                if response != 0:
                    currentVenues = json.loads(response)['response']['venues']
                    for venue in currentVenues:
                        # Get description of venue
                        venueResponse = foursquareAPI.getVenue(venue['id'])
                        if venueResponse != 0:
                            venueDetails = json.loads(
                                venueResponse)['response']['venue']
                            if 'description' in venueDetails:
Exemplo n.º 4
0
def __new_char_f(message):
    if message.text[9:].isspace() or len(message.text) == 9:
        bot.send_message(
            message.chat.id,
            "Character name must be provided. Usage: /new_char <name>")
        return
    name = message.text[9:].split(' ')[1]
    db = database.DBConnection(os.getenv("DB"))
    if not db.get_user_char(message.chat.id, name) is None:
        bot.send_message(message.chat.id,
                         "Character with this name already exists!")
        return
    char = {'name': name, 'stats': {}}

    def _finish():
        finish_db = database.DBConnection(os.getenv("DB"))
        finish_db.set_user_char(message.chat.id, name, char)
        bot.send_message(message.chat.id, "Character successfully created!")

    _cha = __new_char_question_gen(
        None,
        utils.is_msg_stat,
        lambda x: char['stats'].update({'CHA': int(x.text)}),
        None,
        "Invalid input, try again.",
        finishing=True,
        finishing_f=_finish)

    _wis_cha = __new_char_question_gen(
        "What is your character's CHArisma?", utils.is_msg_stat,
        lambda x: char['stats'].update({'WIS': int(x.text)}), _cha,
        "Invalid input, try again.")

    _int_wis = __new_char_question_gen(
        "What is your character's WISdom?", utils.is_msg_stat,
        lambda x: char['stats'].update({'INT': int(x.text)}), _wis_cha,
        "Invalid input, try again.")

    _con_int = __new_char_question_gen(
        "What is your character's INTelligence?", utils.is_msg_stat,
        lambda x: char['stats'].update({'CON': int(x.text)}), _int_wis,
        "Invalid input, try again.")

    _dex_con = __new_char_question_gen(
        "What is your character's CONstitution?", utils.is_msg_stat,
        lambda x: char['stats'].update({'DEX': int(x.text)}), _con_int,
        "Invalid input, try again.")

    _str_dex = __new_char_question_gen(
        "What is your character's DEXterity?", utils.is_msg_stat,
        lambda x: char['stats'].update({'STR': int(x.text)}), _dex_con,
        "Invalid input, try again.")

    _str = __new_char_question_gen("What is your character's STRength?",
                                   None,
                                   None,
                                   _str_dex,
                                   "Invalid input, try again.",
                                   starting=True)

    _str(message)
Exemplo n.º 5
0
 def _finish():
     finish_db = database.DBConnection(os.getenv("DB"))
     finish_db.set_user_char(message.chat.id, name, char)
     bot.send_message(message.chat.id, "Character successfully created!")