Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generate.py #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@


def get_name_suffix(path):
path, _ = os.path.splitext(path)
splited = path.rsplit('-', 1)
if path.count('.tsv'):
splited, _ = os.path.splitext(path)
return splited
else:
path, _ = os.path.splitext(path)
splited = path.rsplit('-', 1)
if len(splited) == 2:
return splited[-1]
return ''
Expand All @@ -38,10 +42,15 @@ def main():
current_dict = data.setdefault(int(suffix) if suffix else None, {})

with open(current_source, 'r') as source_file:
for line in source_file:
code, name = line.strip().split()
current_dict[int(code)] = ensure_unicode(name)

if source_file.name.count('.tsv'):
lines = source_file.readlines()[1:]
for line in lines:
_,_,code,name = line.strip().split()
current_dict[int(code)] = ensure_unicode(name)
else:
for line in source_file:
code, name = line.strip().split()
current_dict[int(code)] = ensure_unicode(name)
result = 'data = {0}'.format(repr(data))
with open(destination, 'w') as destination_file:
print(result, file=destination_file)
Expand Down