Exemplo n.º 1
0
    def purchase_beer(self, beer_barcode, user_barcode):
        """User purchases beer"""
        beer_price = self.bar_database.get_item(beer_barcode,
                                                statement='price')
        user_name, user_id = self.bar_database.get_user(user_barcode)
        user_name = to_ascii_utf8(user_name)
        if beer_price <= self.bar_database.sum_log(user_id):
            # Since the beer_barcode may be both the real barcode or the alternative
            # barcode we need to get the real barcode from the db for the transactions log
            real_beer_barcode = int(
                self.bar_database.get_item(beer_barcode, statement='barcode'))
            self.bar_database.insert_log(user_id,
                                         user_barcode,
                                         "purchase",
                                         beer_price,
                                         item=real_beer_barcode)
            beer_name = self.bar_database.get_item(beer_barcode,
                                                   statement='name')
            beer_name = to_ascii_utf8(beer_name)
            balance = self.bar_database.sum_log(user_id)

            self.picaso.clear_screen()
            self.picaso.move_cursor(1, 0)
            self.picaso.put_string("User: {}".format(user_name))
            self.picaso.move_cursor(3, 0)
            self.picaso.put_string("Beer purchased:")
            self.picaso.move_cursor(4, 0)
            self.picaso.text_factor(2)
            self.picaso.put_string("{}".format(beer_name))
            self.picaso.move_cursor(5, 0)
            self.picaso.text_factor(1)
            self.picaso.put_string("Account balance: {}".format(balance))
            self.timer(3)
        else:
            self.picaso.clear_screen()
            x_screen_resolution = self.picaso.get_graphics_parameters('x_max')
            y_screen_resolution = self.picaso.get_graphics_parameters('y_max')
            self.picaso.draw_filled_rectangle(
                (0, 0), (x_screen_resolution, y_screen_resolution), (1, 0, 0))
            self.picaso.move_cursor(1, 0)
            self.picaso.text_factor(3)
            self.picaso.text_foreground_color((0, 0, 0))
            self.picaso.text_background_color((1, 0, 0))
            self.picaso.put_string("Insufficient")
            self.picaso.move_cursor(2, 0)
            self.picaso.put_string("Funds!")
            self.picaso.move_cursor(4, 0)
            self.picaso.text_factor(2)
            self.picaso.put_string("Get a job")
            self.picaso.text_foreground_color((0, 1, 0))
            self.picaso.text_background_color((0, 0, 0))
            self.timer(5)
Exemplo n.º 2
0
def main():
    """Run the decoding steps"""
    con = MySQLdb.connect('servcinf-sql',
                          'fridays',
                          'fridays',
                          'cinfdata',
                          charset='utf8',
                          use_unicode=False)
    cursor = con.cursor()

    print('\n========= Users ========')
    cursor.execute('select name from fridays_user')
    users = cursor.fetchall()
    for user in users:
        user = user[0]
        print(type(user))
        norm_user = to_ascii_utf8(user)
        try:
            norm_user.encode('ascii')
        except UnicodeDecodeError:
            print('Encoding to ascii failed for this entry')
            print(user)
            raise
        print('Name:    {:<30} -> {}'.format(user, norm_user))

    print('\n========= Items ========')
    cursor.execute('select name, brewery from fridays_items')
    items = cursor.fetchall()
    for name, brewery in items:
        print("--------------------")
        norm_name = to_ascii_utf8(name)
        try:
            norm_name.encode('ascii')
        except UnicodeDecodeError:
            print('Encoding to ascii failed for this entry')
            print(name)
            raise
        print('Name:    {:<30} -> {}'.format(name, norm_name))

        if brewery is None:
            continue
        norm_brewery = to_ascii_utf8(brewery)
        try:
            norm_brewery.encode('ascii')
        except UnicodeDecodeError:
            print('Encoding to ascii failed for this entry')
            print(brewery)
            raise
        print('Brewery: {:<30} -> {}'.format(brewery, norm_brewery))
Exemplo n.º 3
0
 def present_user(self, user_barcode):
     """Present user info, i.e. user name and balance"""
     user_name, user_id = self.bar_database.get_user(user_barcode)
     user_name = to_ascii_utf8(user_name)
     balance = self.bar_database.sum_log(user_id)
     # Screen layout, username
     self.picaso.clear_screen()
     #self.picaso.move_cursor(1, 0)
     self.picaso.move_origin(0, 5)
     self.picaso.put_string("User:"******"Balance:")
     self.picaso.text_factor(3)
     self.picaso.move_cursor(3, 0)
     self.picaso.put_string("{}".format(balance))
     # Timeout
     for number in range(10, 0, -1):
         self.picaso.move_cursor(5, 0)
         self.picaso.put_string("Timeout: {: <2} ".format(number))
         self.timer(1)
Exemplo n.º 4
0
 def present_user(self, user_barcode):
     """Present user info, i.e. user name and balance"""
     user_name, user_id = self.bar_database.get_user(user_barcode)
     user_name = to_ascii_utf8(user_name)
     balance = self.bar_database.sum_log(user_id)
     # Screen layout, username
     self.picaso.clear_screen()
     #self.picaso.move_cursor(1, 0)
     self.picaso.move_origin(0, 5)
     self.picaso.put_string("User:"******"Balance:")
     self.picaso.text_factor(3)
     self.picaso.move_cursor(3, 0)
     self.picaso.put_string("{}".format(balance))
     # Timeout
     for number in range(10, 0, -1):
         self.picaso.move_cursor(5, 0)
         self.picaso.put_string("Timeout: {: <2} ".format(number))
         self.timer(1)
Exemplo n.º 5
0
    def purchase_beer(self, beer_barcode, user_barcode):
        """User purchases beer"""
        beer_price = self.bar_database.get_item(beer_barcode, statement='price')
        user_name, user_id = self.bar_database.get_user(user_barcode)
        user_name = to_ascii_utf8(user_name)
        if beer_price <= self.bar_database.sum_log(user_id):
            # Since the beer_barcode may be both the real barcode or the alternative
            # barcode we need to get the real barcode from the db for the transactions log
            real_beer_barcode = int(self.bar_database.get_item(beer_barcode, statement='barcode'))
            self.bar_database.insert_log(user_id, user_barcode, "purchase", beer_price,
                                         item=real_beer_barcode)
            beer_name = self.bar_database.get_item(beer_barcode, statement='name')
            beer_name = to_ascii_utf8(beer_name)
            balance = self.bar_database.sum_log(user_id)

            self.picaso.clear_screen()
            self.picaso.move_cursor(1, 0)
            self.picaso.put_string("User: {}".format(user_name))
            self.picaso.move_cursor(3, 0)
            self.picaso.put_string("Beer purchased:")
            self.picaso.move_cursor(4, 0)
            self.picaso.text_factor(2)
            self.picaso.put_string("{}".format(beer_name))
            self.picaso.move_cursor(5, 0)
            self.picaso.text_factor(1)
            self.picaso.put_string("Account balance: {}".format(balance))
            self.timer(3)
        else:
            self.picaso.clear_screen()
            x_screen_resolution = self.picaso.get_graphics_parameters('x_max')
            y_screen_resolution = self.picaso.get_graphics_parameters('y_max')
            self.picaso.draw_filled_rectangle(
                (0, 0), (x_screen_resolution, y_screen_resolution), (1, 0, 0)
            )
            self.picaso.move_cursor(1, 0)
            self.picaso.text_factor(3)
            self.picaso.text_foreground_color((0, 0, 0))
            self.picaso.text_background_color((1, 0, 0))
            self.picaso.put_string("Insufficient")
            self.picaso.move_cursor(2, 0)
            self.picaso.put_string("Funds!")
            self.picaso.move_cursor(4, 0)
            self.picaso.text_factor(2)
            self.picaso.put_string("Get a job")
            self.picaso.text_foreground_color((0, 1, 0))
            self.picaso.text_background_color((0, 0, 0))
            self.timer(5)
def main():
    """Run the decoding steps"""
    con = MySQLdb.connect('servcinf', 'fridays', 'fridays', 'cinfdata',
                          charset='utf8', use_unicode=False)
    cursor = con.cursor()

    print('\n========= Users ========')
    cursor.execute('select name from fridays_user')
    users = cursor.fetchall()
    for user in users:
        user = user[0]
        print(type(user))
        norm_user = to_ascii_utf8(user)
        try:
            norm_user.encode('ascii')
        except UnicodeDecodeError:
            print('Encoding to ascii failed for this entry')
            print(user)
            raise
        print('Name:    {:<30} -> {}'.format(user, norm_user))


    print('\n========= Items ========')
    cursor.execute('select name, brewery from fridays_items')
    items = cursor.fetchall()
    for name, brewery in items:
        print("--------------------")
        norm_name = to_ascii_utf8(name)
        try:
            norm_name.encode('ascii')
        except UnicodeDecodeError:
            print('Encoding to ascii failed for this entry')
            print(name)
            raise
        print('Name:    {:<30} -> {}'.format(name, norm_name))

        if brewery is None:
            continue
        norm_brewery = to_ascii_utf8(brewery)
        try:
            norm_brewery.encode('ascii')
        except UnicodeDecodeError:
            print('Encoding to ascii failed for this entry')
            print(brewery)
            raise
        print('Brewery: {:<30} -> {}'.format(brewery, norm_brewery))
Exemplo n.º 7
0
    def present_beer(self, barcode):
        """INSERT Show beer"""
        self.picaso.clear_screen()
        beer_price = str(self.bar_database.get_item(barcode, statement='price'))
        self.picaso.move_cursor(4, 4)
        self.picaso.put_string("Special price for you my friend:")
        self.picaso.move_cursor(7, 5)
        self.picaso.text_factor(5)
        self.picaso.put_string("{} DKK".format(beer_price))

        self.timer(3)
        # INSERT Show spiffy comment
        self.picaso.clear_screen()
        self.picaso.move_cursor(1, 0)
        self.picaso.put_string(cowsay("Enjoy your delicious {}".format(
            to_ascii_utf8(self.bar_database.get_item(barcode, statement='name'))
        )))
        self.timer(4)
Exemplo n.º 8
0
    def present_beer(self, barcode):
        """INSERT Show beer"""
        self.picaso.clear_screen()
        beer_price = str(self.bar_database.get_item(barcode,
                                                    statement='price'))
        self.picaso.move_cursor(4, 4)
        self.picaso.put_string("Special price for you my friend:")
        self.picaso.move_cursor(7, 5)
        self.picaso.text_factor(5)
        self.picaso.put_string("{} DKK".format(beer_price))

        self.timer(3)
        # INSERT Show spiffy comment
        self.picaso.clear_screen()
        self.picaso.move_cursor(1, 0)
        self.picaso.put_string(
            cowsay("Enjoy your delicious {}".format(
                to_ascii_utf8(
                    self.bar_database.get_item(barcode, statement='name')))))
        self.timer(4)