-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace latitude and longitude with one argument alone: --position
- Loading branch information
Jérôme Deuchnord
committed
Jun 20, 2021
1 parent
6ffe0ad
commit 9d2d0cc
Showing
3 changed files
with
44 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import re | ||
|
||
from kosmorrolib import Position | ||
|
||
from .i18n.utils import _ | ||
|
||
|
||
def _parse_latitude_longitude(from_str: str) -> Position: | ||
if not re.search(r"^([\d.-]+)[,;]([\d.-]+)$", from_str): | ||
raise ValueError(_("The given position (%s) is not valid." % from_str)) | ||
|
||
latitude_longitude = from_str.split(';') | ||
if len(latitude_longitude) == 1: | ||
latitude_longitude = from_str.split(',') | ||
|
||
return Position(float(latitude_longitude[0]), float(latitude_longitude[1])) | ||
|
||
|
||
def get_position(from_str: str) -> Position: | ||
return _parse_latitude_longitude(from_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters