Hopefully fix crash on sending "Schöfferhofer" to LCD display

This commit is contained in:
Sebastian Pipping 2011-10-17 21:23:17 +02:00
parent 028d03456f
commit bb468f25bf
2 changed files with 37 additions and 1 deletions

View File

@ -7,6 +7,7 @@
from __future__ import print_function
import freitagslib.network as net
from freitagslib.commands import BuyCommand, DepositCommand
from freitagslib.encoding import asciify
import colorama
from colorama import Fore, Style
@ -332,7 +333,7 @@ class Status:
mylabel="Pfand "+command.commodity_label()[:9]
if (mycmd==3):
mylabel=("%-13s" % (command.commodity_label()[:13]))+"+P"
print_display('\x0b%-15s %4.2f' % (mylabel[:15],abs(command.difference())));
print_display('\x0b%-15s %4.2f' % (asciify(mylabel)[:15],abs(command.difference())));
print_display('\x0b\nSUMME: {%02i} %8.2f' % ((i-1),initial_balance - self.balance));
else:
print_display('\x0b%-15s %4.2f' % (command.label()[:15],abs(command.difference())));

View File

@ -0,0 +1,35 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL v3 or later
from __future__ import print_function
def asciify(utf8):
_mapping = (
('ö', 'oe'),
('Ö', 'Oe'),
('ä', 'ae'),
('Ä', 'Ae'),
('ü', 'ue'),
('Ü', 'Ue'),
('ß', 'ss'),
)
_mapping = dict(((ord(unicode(key, 'utf-8')), value) for key, value in _mapping))
def subst(unichar):
def fix(unichar):
if ord(unichar) > 127:
return unicode('?')
return unichar
return _mapping.get(ord(unichar), fix(unichar))
unichars = utf8.decode('utf-8')
unitext = ''.join(subst(e) for e in unichars)
return unitext.encode('ascii')
if __name__ == '__main__':
print(asciify('Schöfferhofer'))