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

Output specified letter groups in --list #21

Merged
merged 11 commits into from
May 23, 2021
Merged

Output specified letter groups in --list #21

merged 11 commits into from
May 23, 2021

Conversation

Badboy-16
Copy link
Contributor

Trying to fix #19

Usage:

# List all letter groups
$ timezone-converter --list
# List timezones beginning with 'm'
$ timezone-converter --list m
# List timezones beginning with 'b', 'd', or 't'
$ timezone-converter --list bdt

Copy link
Owner

@ibLeDy ibLeDy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments, I hope you don't mind doing some changes.

(clicked approve by mistake, sorry for the confusion)

timezone_converter/main.py Outdated Show resolved Hide resolved
timezone_converter/main.py Outdated Show resolved Hide resolved
timezone_converter/list_view.py Show resolved Hide resolved
timezone_converter/list_view.py Outdated Show resolved Hide resolved
Copy link
Owner

@ibLeDy ibLeDy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments, I hope you don't mind doing some changes.

@ibLeDy ibLeDy self-requested a review May 22, 2021 16:28
@ibLeDy
Copy link
Owner

ibLeDy commented May 22, 2021

I updated the comments, as the suggestion to use [None] as the const value was not really optimal. My improved suggestion is to just use True.

timezone_converter/list_view.py Outdated Show resolved Hide resolved
timezone_converter/list_view.py Outdated Show resolved Hide resolved
@Badboy-16
Copy link
Contributor Author

Thanks for the suggestions from both of you! I pushed some new commits according to the requested changes.

However, for the comparison part in list_view.ListView._sort_and_group, I used if self.letters rather than if self.letters is True, as I found the latter doesn't seem to work when testing the --list output.

I also tested on some pseudo-code in Python shell.

>>> a = ['x', 'y', 'z']
>>> if a is True:
...     print('foo')
... 
>>> if a:
...     print('bar')
... 
bar

@ibLeDy
Copy link
Owner

ibLeDy commented May 23, 2021

Yeah, the suggestion was that we could use True as a value for const, but it was not a really good option. However, using ascii_lowercase solves all issues and aven simplifies the code a bit.

Copy link
Owner

@ibLeDy ibLeDy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment regarding an unnecesary if statement, but this looks good!

def _sort_and_group(self) -> DefaultDict[str, List[str]]:
sorted_timezones = dict(sorted(self.timezone_translations.items()))
longest_name = len(max(sorted_timezones, key=lambda x: len(x)))
timezone_groups: DefaultDict[str, List[str]] = defaultdict(list)
for tz_name in sorted_timezones:
timezone_groups[tz_name[0]].append(tz_name.center(longest_name))
if self.letters:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement is not necessary, as we are using list(string.ascii_lowercase) as a value for const in main.py.

@ibLeDy ibLeDy self-requested a review May 23, 2021 17:04
@ibLeDy
Copy link
Owner

ibLeDy commented May 23, 2021

I seems that I always forget that the request changes button exists, sorry about that.

Please @Badboy-16 , take a look at the comment about the unnecessary if statement. When that is fixed this will be ready to be merged!

@Badboy-16
Copy link
Contributor Author

Have just removed the if statement and the test output looks ok 🎉

@ibLeDy
Copy link
Owner

ibLeDy commented May 23, 2021

Thanks again for your time and for this contribution! I'll create a new release in a bit

@ibLeDy ibLeDy merged commit b03403d into ibLeDy:main May 23, 2021
@Badboy-16 Badboy-16 deleted the 19 branch May 23, 2021 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to output a single letter group
3 participants