architv / soccer-cli

:soccer: Football scores for hackers. :computer: A command line interface for all the football scores.
MIT License
1.09k stars 221 forks source link

optimize with str.format(**dict) #77

Closed cclauss closed 8 years ago

carlosvargas commented 8 years ago

I got an unicode error while trying to run this:

> python -m soccer.main --players --team AFC
 File "soccer\writers.py", line 118, in team_players
    click.secho(fmt.format(**player), bold=True)
 UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 11: ordinal not in range(128)

Therefore, we'll need to make sure the strings are unicode:

    fmt = (u"{jerseyNumber:4} {name:28} {position:23} {nationality:23}"
           u" {dateOfBirth:18} {marketValue}")

Using __future__ import unicode_literals seems to be throwing an error somewhere else (I don't have the time right now to debug it), but if you can fix that, I think using this might be better.

cclauss commented 8 years ago

I made the suggested changes. Sorry about that.

carlosvargas commented 8 years ago

Thanks. If you fix the padding issues, then we'll be good.

Before: image

Now: image

cclauss commented 8 years ago

str.format() left aligns text but right aligns numbers. In this last mod, I forced everything to be left aligned.

carlosvargas commented 8 years ago

Thanks @cclauss! :+1: