Exemplo n.º 1
0
async def below(message):
    """This function should now be able to handle more than just $20.
            This function searches the product dB and displays the first
            ten values under the price input by the user.
        """
    # Substring the user's input to get the integer value.
    below = message.content[6:]
    # Check if the Substring contains a digit.
    if below.isdigit():
        _db = Database.instance(None)
        sel = Select("products", ["product_id"])
        sel.less_than_or_equal_to("sale_price", below)
        products = []
        for product in get_record(sel):
            products.append(product[0])

        rand_products = []
        while rand_products != 10:
            rand_product_id = random.randint(0, len(products) - 1)
            chosen_random_prod = products[rand_product_id][0]
            rand_products.append(chosen_random_prod)
        msg = "The products below ", below, " are: {}".format(
            str(rand_products))
        await message.channel.send(msg)
    else:
        # Simple help response if the user inputs something other than a digit.
        await message.channel.send(
            'Please type a integer after !BELOW'
            '\n Example !BELOW20'
            '\n this will return the first ten items below $20')
Exemplo n.º 2
0
 def test_delete_record(self):
     mp = {"a": "integer"}
     _db = Database.instance(":memory:", "test_table", mp)
     keys = mp.keys()
     create = Create("test_table", keys)
     create_records(keys, create, [{"a": 1}, {"a": 2}])
     sel = Select("test_table", ["a"])
     sel.less_than_or_equal_to("a", 3)
     rvals = []
     for r in get_record(sel):
         rvals.append(r)
     d = Delete("test_table")
     d.greater_than("a", 1)
     delete_record(d)
     sel = Select("test_table", ["a"])
     sel.less_than_or_equal_to("a", 3)
     rvals = []
     for r in get_record(sel):
         rvals.append(r)
Exemplo n.º 3
0
    def query(self):
        """
        Perform the queries. Reset the selector for reuse.

        :return:    Dictionaries of objects
        """
        records = []
        # must use the for loop does not work otherwise
        for row in get_record(self.select):
            record = dict(zip(self._fields, row))
            records.append(record)
        self.select = Select("orders", self._fields)
        return records
Exemplo n.º 4
0
 def test_select(self):
     """
     Test the select
     """
     mp = {"a": "integer"}
     db = Database.instance(":memory:", "test_table", mp)
     keys = mp.keys()
     create = Create("test_table", keys)
     create_records(keys, create, [{"a": 1}, {"a": 2}])
     sel = Select("test_table", ["a"])
     sel.less_than_or_equal_to("a", 3)
     rvals = []
     for r in get_record(sel):
         rvals.append(r)
     assert (len(rvals) > 0)