Skip to content

Commit

Permalink
Detect input file charset
Browse files Browse the repository at this point in the history
  • Loading branch information
jundi committed Aug 23, 2021
1 parent 966091b commit c4642a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions scoresheet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
'''
Reads text file with rows formatted as:
Expand All @@ -20,6 +20,7 @@
import PyPDF2
import appy.pod.renderer
import argcomplete
import charset_normalizer


SEP = ';'
Expand Down Expand Up @@ -68,8 +69,9 @@ def read_file(filename):
:param filename: path to the file
:returns: List of players
"""
# read file
with open(filename) as input_file:
# Read CSV file
encoding = charset_normalizer.from_path(filename).best().encoding
with open(filename, encoding=encoding) as input_file:
reader = csv.reader(input_file, delimiter=';', quotechar='"')
players = list(reader)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
entry_points={
"console_scripts": ["scoresheet=scoresheet:main"]
},
install_requires=['PyPDF2', 'appy', 'argcomplete']
install_requires=['PyPDF2', 'appy', 'argcomplete', 'charset-normalizer']
)

0 comments on commit c4642a0

Please sign in to comment.