From efb60782e91a93a9cc2cb33485e0cf1fc223702b Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Tue, 17 Mar 2020 18:43:35 +0100 Subject: [PATCH 1/3] fixes with logging --- data/.cache.csv | 1 + requirements.txt | 1 + src/tww/common.py | 4 ++++ src/tww/templates/dt.html | 2 +- src/tww/tokenizer.py | 6 +----- src/tww/tww.py | 2 ++ 6 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 data/.cache.csv create mode 100644 src/tww/common.py diff --git a/data/.cache.csv b/data/.cache.csv new file mode 100644 index 0000000..9d4be2f --- /dev/null +++ b/data/.cache.csv @@ -0,0 +1 @@ +zurich,47.3666667,8.5500002 diff --git a/requirements.txt b/requirements.txt index 041f24d..0fd3d9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,6 +29,7 @@ python-dateutil==2.8.1 python-Levenshtein==0.12.0 pytz==2019.3 regex==2020.1.8 +scalpl==0.3.0 six==1.14.0 timezonefinder==4.2.0 traitlets==4.3.3 diff --git a/src/tww/common.py b/src/tww/common.py new file mode 100644 index 0000000..63ed784 --- /dev/null +++ b/src/tww/common.py @@ -0,0 +1,4 @@ +import logging + +logging.basicConfig() +logger = logging.getLogger() diff --git a/src/tww/templates/dt.html b/src/tww/templates/dt.html index 1ee2cd8..8208f44 100644 --- a/src/tww/templates/dt.html +++ b/src/tww/templates/dt.html @@ -21,5 +21,5 @@ var radius = canvas.height / 2; ctx.translate(radius, radius); radius = radius * 0.90; - drawClock(ctx, radius, "{{dst_dt.iso8601_time}}"); + drawClock(ctx, radius, "{{dt.iso8601_time}}"); \ No newline at end of file diff --git a/src/tww/tokenizer.py b/src/tww/tokenizer.py index f7f8d8d..12768a6 100644 --- a/src/tww/tokenizer.py +++ b/src/tww/tokenizer.py @@ -1,7 +1,6 @@ import argparse import json import locale -import logging import re from datetime import datetime @@ -12,6 +11,7 @@ from localization import setlocale, resolve_locale from tww import ISO_FORMAT, time_to_emoji, time_ago, workday_diff, workhours_diff, td_remainders, td_totals, td_iso8601 from tww import resolve_timezone, dateparser_parse_dt, get_utcnow, get_s_since_epoch, get_ms_since_epoch, \ dt_tz_translation, get_local_now, query_to_format_result +from common import logger custom_locale = resolve_locale() @@ -314,10 +314,6 @@ def parse_args(): return args -logging.basicConfig() -logger = logging.getLogger() - - def setup_logging_level(debug=False): log_level = logging.DEBUG if debug else logging.ERROR logger.setLevel(log_level) diff --git a/src/tww/tww.py b/src/tww/tww.py index e61d21c..d9707c1 100644 --- a/src/tww/tww.py +++ b/src/tww/tww.py @@ -29,6 +29,8 @@ from pytz.exceptions import UnknownTimeZoneError from timezonefinder import TimezoneFinder from word2number import w2n +from common import logger + FUZZ_THRESHOLD = 70 ISO_FORMAT = '%Y-%m-%dT%H:%M:%S%z' DEFAULT_FORMAT = '%Y-%m-%d %H:%M:%S%z' From f4075b7bb57e23d5d779c93cd299ec1721cc51b6 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Tue, 17 Mar 2020 19:00:09 +0100 Subject: [PATCH 2/3] change relative --- src/main.py | 6 ++++++ src/tww/localization.py | 2 +- src/tww/tokenizer.py | 15 +++++---------- src/tww/tww.py | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 src/main.py diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..faf41c4 --- /dev/null +++ b/src/main.py @@ -0,0 +1,6 @@ +from tww.tokenizer import parse_args, setup_logging_level, main + +if __name__ == "__main__": + args = parse_args() + setup_logging_level(args.debug) + main(args) \ No newline at end of file diff --git a/src/tww/localization.py b/src/tww/localization.py index 155d7c8..12c0563 100644 --- a/src/tww/localization.py +++ b/src/tww/localization.py @@ -5,7 +5,7 @@ import os from fuzzywuzzy import fuzz -from tww import basepath +from tww.tww import basepath @contextlib.contextmanager diff --git a/src/tww/tokenizer.py b/src/tww/tokenizer.py index 12768a6..f690c4e 100644 --- a/src/tww/tokenizer.py +++ b/src/tww/tokenizer.py @@ -2,16 +2,17 @@ import argparse import json import locale import re +import logging from datetime import datetime from pygments import highlight, lexers, formatters from scalpl import Cut -from localization import setlocale, resolve_locale -from tww import ISO_FORMAT, time_to_emoji, time_ago, workday_diff, workhours_diff, td_remainders, td_totals, td_iso8601 -from tww import resolve_timezone, dateparser_parse_dt, get_utcnow, get_s_since_epoch, get_ms_since_epoch, \ +from tww.localization import setlocale, resolve_locale +from tww.tww import ISO_FORMAT, time_to_emoji, time_ago, workday_diff, workhours_diff, td_remainders, td_totals, td_iso8601 +from tww.tww import resolve_timezone, dateparser_parse_dt, get_utcnow, get_s_since_epoch, get_ms_since_epoch, \ dt_tz_translation, get_local_now, query_to_format_result -from common import logger +from tww.common import logger custom_locale = resolve_locale() @@ -329,9 +330,3 @@ def main(args): if args.full: pretty_print_dict(result) show_magic_results(result, args) - - -if __name__ == "__main__": - args = parse_args() - setup_logging_level(args.debug) - main(args) diff --git a/src/tww/tww.py b/src/tww/tww.py index d9707c1..1bd690b 100644 --- a/src/tww/tww.py +++ b/src/tww/tww.py @@ -29,7 +29,7 @@ from pytz.exceptions import UnknownTimeZoneError from timezonefinder import TimezoneFinder from word2number import w2n -from common import logger +from tww.common import logger FUZZ_THRESHOLD = 70 ISO_FORMAT = '%Y-%m-%dT%H:%M:%S%z' From 31a30225fd4af06af72d0acf9522764f96ed3a51 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Wed, 18 Mar 2020 12:06:53 +0100 Subject: [PATCH 3/3] update setup --- .gitignore | 1 + requirements.txt | 2 +- setup.py | 88 ++++++++++++++++++++++++------------------------ src/main.py | 2 +- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index aabd304..ca6e2e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ venv src/tww/data/.cache.csv __pycache__ .idea +tww.egg-info \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0fd3d9d..86f3af1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ backcall==0.1.0 chardet==3.0.4 -Click==7.0 +click==7.1.1 dateparser==0.7.2 DateTimeRange==0.6.1 decorator==4.4.1 diff --git a/setup.py b/setup.py index 67a5b1b..8e20596 100644 --- a/setup.py +++ b/setup.py @@ -2,56 +2,56 @@ from setuptools import setup def gen_from_file(): - return [ - 'backcall==0.1.0', - 'chardet==3.0.4', - 'Click==7.0', - 'dateparser==0.7.2', - 'DateTimeRange==0.6.1', - 'decorator==4.4.1', - 'Flask==1.1.1', - 'freezegun==0.3.14', - 'fuzzywuzzy==0.18.0', - 'geographiclib==1.50', - 'geopy==1.21.0', - 'importlib-resources==1.0.2', - 'ipython==7.12.0', - 'ipython-genutils==0.2.0', - 'isodate==0.6.0', - 'itsdangerous==1.1.0', - 'jedi==0.16.0', - 'Jinja2==2.11.1', - 'MarkupSafe==1.1.1', - 'mbstrdecoder==0.8.4', - 'numpy==1.18.1', - 'parso==0.6.1', - 'pexpect==4.8.0', - 'pickleshare==0.7.5', - 'prompt-toolkit==3.0.3', - 'ptyprocess==0.6.0', - 'Pygments==2.5.2', - 'python-dateutil==2.8.1', - 'python-Levenshtein==0.12.0', - 'pytz==2019.3', - 'regex==2020.1.8', - 'six==1.14.0', - 'timezonefinder==4.2.0', - 'traitlets==4.3.3', - 'typepy==0.6.5', - 'tzlocal==2.0.0', - 'wcwidth==0.1.8', - 'Werkzeug==1.0.0', - 'word2number==1.1', - ] - # with open("requirements.txt") as f: - # return [line.strip() for line in f.readlines()] + # return [ + # 'backcall==0.1.0', + # 'chardet==3.0.4', + # 'Click==7.0', + # 'dateparser==0.7.2', + # 'DateTimeRange==0.6.1', + # 'decorator==4.4.1', + # 'Flask==1.1.1', + # 'freezegun==0.3.14', + # 'fuzzywuzzy==0.18.0', + # 'geographiclib==1.50', + # 'geopy==1.21.0', + # 'importlib-resources==1.0.2', + # 'ipython==7.12.0', + # 'ipython-genutils==0.2.0', + # 'isodate==0.6.0', + # 'itsdangerous==1.1.0', + # 'jedi==0.16.0', + # 'Jinja2==2.11.1', + # 'MarkupSafe==1.1.1', + # 'mbstrdecoder==0.8.4', + # 'numpy==1.18.1', + # 'parso==0.6.1', + # 'pexpect==4.8.0', + # 'pickleshare==0.7.5', + # 'prompt-toolkit==3.0.3', + # 'ptyprocess==0.6.0', + # 'Pygments==2.5.2', + # 'python-dateutil==2.8.1', + # 'python-Levenshtein==0.12.0', + # 'pytz==2019.3', + # 'regex==2020.1.8', + # 'six==1.14.0', + # 'timezonefinder==4.2.0', + # 'traitlets==4.3.3', + # 'typepy==0.6.5', + # 'tzlocal==2.0.0', + # 'wcwidth==0.1.8', + # 'Werkzeug==1.0.0', + # 'word2number==1.1', + # ] + with open("requirements.txt") as f: + return [line.strip() for line in f.readlines()] setup(name='tww', version='0.2', description='Time When and Where', url='http://gitlab.com/pisquared/tww', - author='Flying Circus', + author='Daniel Tsvetkov', install_requires=gen_from_file(), author_email='', license='MIT', diff --git a/src/main.py b/src/main.py index faf41c4..14373da 100644 --- a/src/main.py +++ b/src/main.py @@ -3,4 +3,4 @@ from tww.tokenizer import parse_args, setup_logging_level, main if __name__ == "__main__": args = parse_args() setup_logging_level(args.debug) - main(args) \ No newline at end of file + main(args)