From 4b5122ab3966cf147621880b1da1155677c95dff Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Tue, 11 May 2021 15:25:50 +0200 Subject: [PATCH] more logging, more ideas --- README.md | 29 +++++++++++++++++++++++++++-- tww/lib.py | 10 ++++++++-- tww/tokenizer.py | 2 ++ tww/web.py | 1 - 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f8cd111..59ec770 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,12 @@ python tww QUERY [--debug] [--full] ``` * Supported `QUERY` types: + - Just time: ``: + - `now` + - `in 5 hours` + - `5 January 2012` + - `4:26 PM` + - `April 2020` - Timezone translation ` in to ` or ` to ` (assumes datetime is `local`) - `04:26 in japan to local` - `03:14 in local to IST` @@ -19,8 +25,7 @@ python tww QUERY [--debug] [--full] - (Approximate) workdays calculation (assumes monday-friday are work days - ignores public/local holidays (for now)): `work days/hours since/until ` or ` - `workdays since 2021-01-05` - `work hours until Friday` - - Milliseconds since epoch: `(time/seconds) since epoch` - - Datetime to epoch: ` to epoch` or `(milli)seconds since /epoch` + - Milliseconds since epoch: `(time/(milli)seconds) since epoch` or datetime to epoch: ` to epoch` or `(milli)seconds since /epoch` - `2021-01:01 to epoch` - `milliseconds since epoch` @@ -93,3 +98,23 @@ Time in one timezone (pst) to another in city: $ tww 3/14 15 9:26:53 PST to sofia 2015-03-14 19:26:53+02:00 ``` + + +## TODO +* Calculate time differences: + - parse `timedelta`: + - `(%d) (?year|month|week|day|hour|minute|second)[s]?` + - calculate: + - ` (?\+|\-|plus|minus) ` + - `12-12-2019 + 2 weeks` + - `05:23 - 150 minutes` + - ` (before|from)
` + - `3 days from next Friday` + - `2 hours before 15:00` +* Day of the week + - `what day is
` +* Return Time range + - parse relative to now: + - `(previous|last|this|next) (year|month|week|day|hour|minute|second|Monday|Tuesday|...|Sunday)` + +* [Countries names in their own languages](https://www.worldatlas.com/articles/names-of-countries-in-their-own-languages.html), [list of countries in various languages](https://en.wikipedia.org/wiki/List_of_country_names_in_various_languages_(A%E2%80%93C)) \ No newline at end of file diff --git a/tww/lib.py b/tww/lib.py index 6873835..6b0d621 100644 --- a/tww/lib.py +++ b/tww/lib.py @@ -584,8 +584,10 @@ def dateparser_parse_dt(s: str): s = custom_dt_parse(s) s = regex_parsers(s) parsed = parse_dt(s) + logger.debug("Parse dt: {}".format(parsed)) if not parsed: parsed = dutil_parse(s) + logger.debug("dutil_parse: {}".format(parsed)) if not parsed: return None if parsed.tzinfo is None: @@ -601,8 +603,12 @@ def get_utcnow(tzaware: bool = True): def get_local_now(tzaware: bool = True): if tzaware: - return datetime.now().replace(tzinfo=tzinfo_from_offset(get_local_tz_offset())[0]) - return datetime.utcnow() + dt = datetime.now().replace(tzinfo=tzinfo_from_offset(get_local_tz_offset())[0]) + logger.debug("Local now (tzaware): {}".format(dt)) + return dt + dt = datetime.utcnow() + logger.debug("Local now (utc): {}".format(dt)) + return dt def split_offset(offset): diff --git a/tww/tokenizer.py b/tww/tokenizer.py index 1c1ef1e..1b26d19 100644 --- a/tww/tokenizer.py +++ b/tww/tokenizer.py @@ -56,8 +56,10 @@ def handler_time_now_utc(): def dt_normalize(start_dt, end_dt) -> (datetime, datetime): if type(start_dt) is str: start_dt = dateparser_parse_dt(start_dt) + logger.debug("Start time: {}".format(start_dt)) if type(end_dt) is str: end_dt = dateparser_parse_dt(end_dt) + logger.debug("End time: {}".format(end_dt)) return start_dt, end_dt diff --git a/tww/web.py b/tww/web.py index 8d18145..9274d68 100644 --- a/tww/web.py +++ b/tww/web.py @@ -107,7 +107,6 @@ def render_solution(solution): return render_template("td.html", **solution) - def render_solutions(results): rv = [] for solution in results['solutions']: