From 99959e7bdc1258d6d5339d79d01c81aec7c6f2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Hane=C4=8D=C3=A1k?= Date: Tue, 4 Jan 2022 20:20:49 +0100 Subject: [PATCH 1/3] feat: added --definitions and --explain commands, support for KOSMORO_EXPLAIN env variable --- _kosmorro/main.py | 44 +++++++++++++++++++++++++++ _kosmorro/terms.py | 35 +++++++++++++++++++++ manpage/kosmorro.7.md | 71 ------------------------------------------- 3 files changed, 79 insertions(+), 71 deletions(-) create mode 100644 _kosmorro/terms.py delete mode 100644 manpage/kosmorro.7.md diff --git a/_kosmorro/main.py b/_kosmorro/main.py index d8ef013..2b71248 100644 --- a/_kosmorro/main.py +++ b/_kosmorro/main.py @@ -38,6 +38,7 @@ from .exceptions import ( OutOfRangeDateError as DateRangeError, ) from _kosmorro.i18n.utils import _, SHORT_DATE_FORMAT +from .terms import terms as term_dictionary def main(): @@ -50,6 +51,13 @@ def main(): if args.special_action is not None: return 0 if args.special_action() else 1 + + if args.definitions is not None: + for term in term_dictionary: + print_term(term) + return 0 + + try: compute_date = parse_date(args.date) except ValueError as error: @@ -122,6 +130,8 @@ def main(): debug.debug_print(error) return 1 + + if args.output is not None: try: file_content = output.to_string() @@ -146,6 +156,17 @@ def main(): return 3 elif not output.is_file_output_needed(): print(output) + + if args.explain is not None or env_vars.explain is not None: + events = [] + for event in output.events: + events.append(event.event_type.name) + + events = list(dict.fromkeys(events)) + for event in events: + for term in term_dictionary: + if event.lower() == term.lower(): + print_term(term) else: print( colored( @@ -240,6 +261,13 @@ def output_version() -> bool: return True +def print_term(term): + print() + print(colored(_('{key_term}\n').format( + key_term = term + ),attrs=['bold'])) + print(_('{explanation}\n').format( + explanation = term_dictionary[term])) def get_args(output_formats: [str]): today = date.today() @@ -336,5 +364,21 @@ def get_args(output_formats: [str]): action="store_true", help=_("Show debugging messages"), ) + parser.add_argument( + "--explain", + default=None, + action="store_true", + help=_( + "Explanation of terms shown by current command output." + ), + ) + parser.add_argument( + "--definitions", + default=None, + action="store_true", + help=_( + "List of kosmorro terms. Program wont provide any calculations!" + ), + ) return parser.parse_args() diff --git a/_kosmorro/terms.py b/_kosmorro/terms.py new file mode 100644 index 0000000..e5cc7a5 --- /dev/null +++ b/_kosmorro/terms.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# Kosmorro - Compute The Next Ephemerides +# Copyright (C) 2019 Jérôme Deuchnord +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +terms = { + "Apogee" : "The Moon is told being at its apogee when it is at its furthest point from the Earth.", + "Conjunction" : "From the point of view of the Earth, two asters are said in conjunction when they are close together.\nIt is, of course, an illusion caused by the position of the Earth combined with the two other objects' ones.", + "Elongation" : "The elongation is the angle of visual separation between a planet and the Sun, as seen from the point of view of the Earth. \nFor the inferior planets, the time when the elongation is maximal is propice to their observation, because it is the moment when they are the most visible.", + "Occultation" : "An occultation is a special kind of conjunction where the closer aster to the Earth hides, at least partially, another one.", + "Opposition" : "An aster is said in opposition when it is positionned at the exact opposite of the Sun, from the point of view of the Earth,\ni.e. when their angle is equal to 180 degrees.\nFor all the superior planets, it is the best moment to observe them, because they will be at the smallest distance to the Earth.\nPlus, they will appear full. For instance, Mars is in opposition when the angle Mars-Earth-Sun is equal to 180 degrees.", + "Perigee" : "The Moon is told being at its apogee when it is at its nearest point from the Earth.", + "Planet" : "A planet is an aster that orbits around a star, is not a star itself, is massive enough to maintain it nearly round,\nand has cleaned its orbit from other massive objects.", + "Inferior planet" : "A planet is said \"inferior\" if its orbit radius is smaller than the planet of reference.\nFor instance, the inferior planets from the point of view of the Earth are Mercury and Venus.\nThe term should not be confused with \"inner planet\".", + "Inner planet" : "The \"inner planet\" term refers to the planets orbiting below the orbit of the asteroid belt between Mars and Jupiter.", + "Outer planet" : "The \"outer planet\" term refers to the planets orbiting beyond the orbit of the asteroid belt between Mars and Jupiter.", + "Superior planet" : "A planet is said \"superior\" if its orbit radius is higher than the planet of reference.\nFor instance, the superior planets from the point of view of the Earth are Mars, Jupiter, Saturn, Uranus and Neptune.\nThe term should not be confused with \"outer planet\"." + } + + + diff --git a/manpage/kosmorro.7.md b/manpage/kosmorro.7.md deleted file mode 100644 index 27e468b..0000000 --- a/manpage/kosmorro.7.md +++ /dev/null @@ -1,71 +0,0 @@ -# kosmorro(7) -- a program that computes the ephemerides - -## DESCRIPTION - -This manual explains the different terms that one can find when using **kosmorro**(1). -The terms are given in an alphabetically order. - -## TERMS - -### Apogee - -The Moon is told being at its apogee when it is at its furthest point from the Earth. - -### Conjunction - -From the point of view of the Earth, two asters are said in conjunction when they are close together. -It is, of course, an illusion caused by the position of the Earth combined with the two other objects' ones. - -### Elongation - -The elongation is the angle of visual separation between a planet and the Sun, as seen from the point of view of the Earth. -For the inferior planets, the time when the elongation is maximal is propice to their observation, because it is the moment when they are the most visible. - -### Occultation - -An occultation is a special kind of conjunction where the closer aster to the Earth hides, at least partially, another one. - -### Opposition - -An aster is said in opposition when it is positionned at the exact opposite of the Sun, from the point of view of the Earth, i.e. when their angle is equal to 180 degrees. -For all the superior planets, it is the best moment to observe them, because they will be at the smallest distance to the Earth. Plus, they will appear full. -For instance, Mars is in opposition when the angle Mars-Earth-Sun is equal to 180 degrees. - -### Perigee - -The Moon is told being at its apogee when it is at its nearest point from the Earth. - -### Planet - -A planet is an aster that orbits around a star, is not a star itself, is massive enough to maintain it nearly round, and has cleaned its orbit from other massive objects. - -**Inferior planet** - -A planet is said "inferior" if its orbit radius is smaller than the planet of reference. -For instance, the inferior planets from the point of view of the Earth are Mercury and Venus. - -The term should not be confused with "inner planet". - -**Inner planet** - -The "inner planet" term refers to the planets orbiting below the orbit of the asteroid belt between Mars and Jupiter. - -**Outer planet** - -The "outer planet" term refers to the planets orbiting beyond the orbit of the asteroid belt between Mars and Jupiter. - -**Superior planet** - -A planet is said "superior" if its orbit radius is higher than the planet of reference. -For instance, the superior planets from the point of view of the Earth are Mars, Jupiter, Saturn, Uranus and Neptune. - -The term should not be confused with "outer planet". - -## AUTHOR - -Written by Jérôme Deuchnord. - -## COPYRIGHT - -This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - From b63e0d29bcf95aa7969d4867428baa98ba16a405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Hane=C4=8D=C3=A1k?= Date: Tue, 4 Jan 2022 22:54:59 +0100 Subject: [PATCH 2/3] fix: fix code style after testing --- _kosmorro/main.py | 19 ++++--------------- _kosmorro/terms.py | 27 ++++++++++++--------------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/_kosmorro/main.py b/_kosmorro/main.py index 2b71248..2e4bcae 100644 --- a/_kosmorro/main.py +++ b/_kosmorro/main.py @@ -51,13 +51,11 @@ def main(): if args.special_action is not None: return 0 if args.special_action() else 1 - if args.definitions is not None: for term in term_dictionary: print_term(term) return 0 - try: compute_date = parse_date(args.date) except ValueError as error: @@ -130,8 +128,6 @@ def main(): debug.debug_print(error) return 1 - - if args.output is not None: try: file_content = output.to_string() @@ -263,11 +259,8 @@ def output_version() -> bool: def print_term(term): print() - print(colored(_('{key_term}\n').format( - key_term = term - ),attrs=['bold'])) - print(_('{explanation}\n').format( - explanation = term_dictionary[term])) + print(colored(_('{key_term}\n').format(key_term = term),attrs=['bold'])) + print(_('{explanation}\n').format(explanation = term_dictionary[term])) def get_args(output_formats: [str]): today = date.today() @@ -368,17 +361,13 @@ def get_args(output_formats: [str]): "--explain", default=None, action="store_true", - help=_( - "Explanation of terms shown by current command output." - ), + help=_("Explanation of terms shown by current command output."), ) parser.add_argument( "--definitions", default=None, action="store_true", - help=_( - "List of kosmorro terms. Program wont provide any calculations!" - ), + help=_("List of kosmorro terms. Program wont provide any calculations!"), ) return parser.parse_args() diff --git a/_kosmorro/terms.py b/_kosmorro/terms.py index e5cc7a5..495f5b3 100644 --- a/_kosmorro/terms.py +++ b/_kosmorro/terms.py @@ -18,18 +18,15 @@ terms = { - "Apogee" : "The Moon is told being at its apogee when it is at its furthest point from the Earth.", - "Conjunction" : "From the point of view of the Earth, two asters are said in conjunction when they are close together.\nIt is, of course, an illusion caused by the position of the Earth combined with the two other objects' ones.", - "Elongation" : "The elongation is the angle of visual separation between a planet and the Sun, as seen from the point of view of the Earth. \nFor the inferior planets, the time when the elongation is maximal is propice to their observation, because it is the moment when they are the most visible.", - "Occultation" : "An occultation is a special kind of conjunction where the closer aster to the Earth hides, at least partially, another one.", - "Opposition" : "An aster is said in opposition when it is positionned at the exact opposite of the Sun, from the point of view of the Earth,\ni.e. when their angle is equal to 180 degrees.\nFor all the superior planets, it is the best moment to observe them, because they will be at the smallest distance to the Earth.\nPlus, they will appear full. For instance, Mars is in opposition when the angle Mars-Earth-Sun is equal to 180 degrees.", - "Perigee" : "The Moon is told being at its apogee when it is at its nearest point from the Earth.", - "Planet" : "A planet is an aster that orbits around a star, is not a star itself, is massive enough to maintain it nearly round,\nand has cleaned its orbit from other massive objects.", - "Inferior planet" : "A planet is said \"inferior\" if its orbit radius is smaller than the planet of reference.\nFor instance, the inferior planets from the point of view of the Earth are Mercury and Venus.\nThe term should not be confused with \"inner planet\".", - "Inner planet" : "The \"inner planet\" term refers to the planets orbiting below the orbit of the asteroid belt between Mars and Jupiter.", - "Outer planet" : "The \"outer planet\" term refers to the planets orbiting beyond the orbit of the asteroid belt between Mars and Jupiter.", - "Superior planet" : "A planet is said \"superior\" if its orbit radius is higher than the planet of reference.\nFor instance, the superior planets from the point of view of the Earth are Mars, Jupiter, Saturn, Uranus and Neptune.\nThe term should not be confused with \"outer planet\"." - } - - - + "Apogee": "The Moon is told being at its apogee when it is at its furthest point from the Earth.", + "Conjunction": "From the point of view of the Earth, two asters are said in conjunction when they are close together.\nIt is, of course, an illusion caused by the position of the Earth combined with the two other objects' ones.", + "Elongation": "The elongation is the angle of visual separation between a planet and the Sun, as seen from the point of view of the Earth. \nFor the inferior planets, the time when the elongation is maximal is propice to their observation, because it is the moment when they are the most visible.", + "Occultation": "An occultation is a special kind of conjunction where the closer aster to the Earth hides, at least partially, another one.", + "Opposition": "An aster is said in opposition when it is positionned at the exact opposite of the Sun, from the point of view of the Earth,\ni.e. when their angle is equal to 180 degrees.\nFor all the superior planets, it is the best moment to observe them, because they will be at the smallest distance to the Earth.\nPlus, they will appear full. For instance, Mars is in opposition when the angle Mars-Earth-Sun is equal to 180 degrees.", + "Perigee": "The Moon is told being at its apogee when it is at its nearest point from the Earth.", + "Planet": "A planet is an aster that orbits around a star, is not a star itself, is massive enough to maintain it nearly round,\nand has cleaned its orbit from other massive objects.", + "Inferior planet": "A planet is said \"inferior\" if its orbit radius is smaller than the planet of reference.\nFor instance, the inferior planets from the point of view of the Earth are Mercury and Venus.\nThe term should not be confused with \"inner planet\".", + "Inner planet": "The \"inner planet\" term refers to the planets orbiting below the orbit of the asteroid belt between Mars and Jupiter.", + "Outer planet": "The \"outer planet\" term refers to the planets orbiting beyond the orbit of the asteroid belt between Mars and Jupiter.", + "Superior planet": "A planet is said \"superior\" if its orbit radius is higher than the planet of reference.\nFor instance, the superior planets from the point of view of the Earth are Mars, Jupiter, Saturn, Uranus and Neptune.\nThe term should not be confused with \"outer planet\".", +} \ No newline at end of file From 0e8013d3abe4d61f711f0ce0881b864b997d6039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Hane=C4=8D=C3=A1k?= Date: Tue, 4 Jan 2022 23:07:26 +0100 Subject: [PATCH 3/3] fix: fix code review --- _kosmorro/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/_kosmorro/main.py b/_kosmorro/main.py index 2e4bcae..eb65d10 100644 --- a/_kosmorro/main.py +++ b/_kosmorro/main.py @@ -347,9 +347,7 @@ def get_args(output_formats: [str]): "--no-graph", dest="show_graph", action="store_false", - help=_( - "Do not generate a graph to represent the rise and set times in the PDF format." - ), + help=_("Do not generate a graph to represent the rise and set times in the PDF format."), ) parser.add_argument( "--debug",