Skip to content

Commit f6c62c6

Browse files
committed
Improved docs
1 parent 007fd20 commit f6c62c6

File tree

8 files changed

+250
-95
lines changed

8 files changed

+250
-95
lines changed

Justfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ update:
2626
{{PIP}} install -U \
2727
build \
2828
pytest \
29+
docutils \
2930
pytest-sugar \
3031
pytest-clarity \
3132
freezegun \
@@ -132,3 +133,8 @@ strftime:
132133
f"Format Specifiers:\n{pt.get_string()}\n\n"
133134
"Notes:\n* - Locale-dependent\n+ - C99 extension\n! - when extension"
134135
)
136+
137+
# Preview README.rst
138+
docs:
139+
rst2html5 --output README.html README.rst
140+
open README.html

README.rst

Lines changed: 164 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
=========
12
when 🌐🕐
23
=========
34

@@ -17,64 +18,113 @@ Scenario
1718
--------
1819

1920
Your favorite sporting event, concert, performance, conference, or symposium is happening
20-
in Ulan Bator and all you know is the time of event is relative to the location city or time zone.
21-
But wait! You need to know when that occurs relative to you while traveling to Seoul or Paris.
21+
in Ulan Bator and all you know is the time of event relative to the city or time zone.
22+
So what time is that for you in your local time? What time did it or will it occur at some
23+
other time? What about for your friends in other locations around the world?
24+
25+
Features
26+
--------
27+
28+
``when`` can refer to source and target locations via the ``--source`` and ``--target`` specifiers.
29+
30+
* ``when`` can download a GeoNames_ cities database for referencing locations by city name
31+
* All IANA time zone definitions are available, as well as the most common time zone aliases (i.e.: ``EST`` => ``US/Eastern``)
32+
* Display current lunar state
33+
* List common holidays for a given country and/or year (US or configurable)
34+
* Show dates for full moons
35+
* Extensive configuration options for results
36+
* JSON output
2237

2338
Installation
24-
------------
39+
============
40+
41+
Install from PyPI:
2542

26-
Install from PyPI::
43+
.. code:: bash
2744
2845
$ pip install when
2946
30-
or using pipx_::
47+
or using pipx_:
48+
49+
.. code:: bash
3150
3251
$ pipx install when
3352
34-
or::
53+
or:
54+
55+
.. code:: bash
3556
3657
$ pipx install git+https://github.com/dakrauth/when.git
3758
38-
.. _pipx: https://pypa.github.io/pipx/
59+
.. note::
60+
61+
Once installed, if you wish to utilize ``when``'s full capabilities, you should
62+
install the GeoNames cities database as describe next.
3963

40-
To access city names, you must install the cities database::
64+
65+
66+
Database installation
67+
---------------------
68+
69+
To access city names, you need to install the cities database after installing the ``when`` application:
70+
71+
.. code:: bash
4172
4273
when --db [options]
4374
44-
For ``options``:
75+
Where ``options`` are:
76+
77+
* ``--db-size``: You can specify a database down size by using one of the following:
78+
79+
* ``sm`` - cities with population > 15,000 + country capitals (~2.9M download, ~2M DB)
80+
* ``md`` - **default**, same as ``sm``, plus:
81+
82+
* cities with population > 5,000 (~4.8M download, ~3.1M DB)
83+
* seat of first-order admin division, i.e. US state
84+
85+
* ``lg`` - same as ``md``, plus:
86+
87+
* cities with population > 1,000 (~9.5M download, ~5.8M DB)
88+
* seat of admin division down to third level (counties)
89+
90+
* ``xl`` - same as ``lg``, plus:
91+
92+
* cities with population > 500 (~12.1M download, ~7.2M DB)
93+
* seat of admin division down to fourth order
4594

46-
You can specify minimum city size by adding ``--size SIZE``, where *SIZE* can be one of:
95+
* ``--db-pop``: Filter non-admin division seats providing a minimum city population size
96+
* ``--db-force``: Force an existing database to be overwritten
4797

48-
- ``15000`` - cities with population > 15000 or country capitals
49-
- ``5000`` - cities with population > 5000 or seat of first-order admin division, i.e. US state
50-
- ``1000`` - cities with population > 1000 or seat of third order admin division
51-
- ``500`` - cities with population > 500 or seat of fourth-order admin division
98+
Database Usage
99+
==============
52100

53-
Additionally, you can filter non-admin division seats using ``--pop POP``.
101+
* Search: ``--db-search``
54102

55-
The appropriate GeoNames Gazetteer is downloaded and a Sqlite database generated.
103+
Once installed, you can search the database:
56104

57-
Usage
58-
-----
105+
.. code:: bash
59106
60-
Once installed, you can search the database::
107+
$ when --db-search New York
108+
5106292, West New York, West New York, US, New Jersey, America/New_York
109+
5128581, New York City, New York City, US, New York, America/New_York
61110
62-
$ when --db-search New York
63-
5106292, West New York, West New York, US, New Jersey, America/New_York
64-
5128581, New York City, New York City, US, New York, America/New_York
111+
* Aliases: ``--db-alias``
65112

113+
You can add aliases for easier search. In the example directly above, we see that New York City has
114+
a GeoNames ID of 5128581. Pass that to the ``--db-alias`` option along with another name that
115+
you would like to use:
66116

67-
Additionally, you can add aliases. In the example directly above, we see that New York City has
68-
a GeoNames ID of 5128581. Pass that to the ``--db-alias`` option along with another name that
69-
you would like to use::
117+
.. code:: bash
70118
71-
$ when --db-alias 5128581 NYC
72-
$ when --source NYC
73-
2023-07-06 07:58:33-0400 (EDT, America/New_York) 187d27w (New York City, New York, US)[🌕 Full Moon]
119+
$ when --db-alias 5128581 NYC
120+
$ when --source NYC
121+
2023-07-06 07:58:33-0400 (EDT, America/New_York) 187d27w (New York City, New York, US)[🌕 Full Moon]
74122
123+
* Alias listing: ``--db-aliases``
75124

76-
Example
77-
-------
125+
126+
Examples
127+
========
78128

79129
For the sake of clarity, in the following examples I am in Seoul, Korea.
80130

@@ -101,24 +151,100 @@ For the sake of clarity, in the following examples I am in Seoul, Korea.
101151
1945-03-07 22:00:00-0400 (EWT, America/New_York) 066d10w [🌘 Waning Crescent]
102152
103153
104-
Develop
105-
-------
154+
Development
155+
===========
106156

107-
Requirements Python 3.10+. Also, [just](https://github.com/casey/just) for convenience.
157+
Requires Python 3.10+ and just_ for convenience.
108158

109159
.. code:: bash
110160
111161
$ git clone git@github.com:dakrauth/when.git
112162
$ cd when
113-
$ just
114-
$ just venv
163+
$ just # or just help
164+
165+
Set up dev env:
166+
167+
.. code:: bash
168+
169+
$ just init
170+
171+
Test, and code coverage:
172+
173+
.. code:: bash
174+
115175
$ just test
176+
$ just cov
177+
178+
Only run a test matching matching a given substring:
179+
180+
.. code:: bash
181+
182+
$ just test -k test_sometest
183+
184+
Interactive development:
185+
186+
.. code:: bash
187+
116188
$ . ./venv/bin/activate
117189
$ when --help
118190
$ when --db
119191
120192
Further Reading
121-
---------------
193+
===============
194+
195+
`Time Zones Aren’t Offsets – Offsets Aren’t Time Zones`_
196+
197+
.. _pipx: https://pypa.github.io/pipx/
198+
.. _just: https://github.com/casey/just
199+
.. _`Time Zones Aren’t Offsets – Offsets Aren’t Time Zones`: https://spin.atomicobject.com/time-zones-offsets/)
200+
.. _GeoNames: https://www.geonames.org/export/
201+
202+
Complete Usage
203+
==============
204+
205+
.. code:: bash
206+
207+
usage: when [--delta {long,short}] [--offset [+-]?(\d+wdhm)+] [-h] [--prefix] [-s SOURCE] [-t TARGET] [-f FORMAT] [-g] [--all]
208+
[--holidays COUNTRY_CODE] [-v] [-V] [--json] [--config] [--db] [--db-force] [--db-search] [--exact] [--db-alias DB_ALIAS]
209+
[--db-aliases] [--db-size DB_SIZE] [--db-pop DB_POP] [--tz-alias] [--fullmoon]
210+
[timestr ...]
211+
212+
Convert times to and from time zones or cities
213+
214+
positional arguments:
215+
timestr Timestamp to parse, defaults to local time
216+
217+
options:
218+
--delta {long,short} Show the delta to the given timestamp
219+
--offset [+-]?(\d+wdhm)+
220+
Show the difference from a given offset
221+
-h, --help Show helpful usage information
222+
--prefix Show when's directory
223+
-s SOURCE, --source SOURCE
224+
Timezone / city to convert the timestr from, defaulting to local time
225+
-t TARGET, --target TARGET
226+
Timezone / city to convert the timestr to (globbing patterns allowed, can be comma delimited), defaulting to local
227+
time
228+
-f FORMAT, --format FORMAT
229+
Output formatting. Additional formats can be shown using the -v option with -h
230+
-g, --group Group sources together under same target results
231+
--all Show times in all common timezones
232+
--holidays COUNTRY_CODE
233+
Show holidays for given country code.
234+
-v, --verbosity Verbosity (-v, -vv, etc). Use -v to show `when` extension detailed help
235+
-V, --version show program's version number and exit
236+
--json Output results in nicely formatted JSON
237+
--config Toggle config mode. With no other option, dump current configuration settings
238+
--db Create cities database, used with --db-size and --db-pop
239+
--db-force Force an existing database to be overwritten
240+
--db-search Search database for the given city
241+
--exact DB searches must be exact
242+
--db-alias DB_ALIAS Create a new alias from the city id
243+
--db-aliases Show all DB aliases
244+
--db-size DB_SIZE Geonames file size. Can be one of 'xl' ('xlarge'), 'lg' ('large'), 'md' ('medium'), 'sm' ('small').
245+
--db-pop DB_POP City population minimum.
246+
--tz-alias Search for a time zone alias
247+
--fullmoon Show full moon(s) for given year or month. Can be in the format of: 'next' | 'prev' | YYYY[-MM]
248+
249+
Use -v option for details
122250
123-
[Time Zones Aren’t Offsets – Offsets Aren’t Time Zones
124-
](https://spin.atomicobject.com/time-zones-offsets/)

src/when/cli.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#!/usr/bin/env python
22
import argparse
3-
import logging
43
import sys
4+
import logging
55
from pathlib import Path
66

77
from . import __version__, core, db, utils, lunar, exceptions
88
from . import timezones
99
from .config import Settings, __doc__ as FORMAT_HELP
1010

11-
logger = logging.getLogger(__name__)
12-
1311

1412
def get_parser(settings):
1513
class DBSizeAction(argparse.Action):
@@ -227,11 +225,14 @@ def log_config(verbosity, settings):
227225
logging.getLogger("asyncio").setLevel(logging.WARNING)
228226

229227
logging.basicConfig(level=log_level, format=log_format, force=True)
228+
logger = utils.logger()
230229
logger.debug(
231230
"Configuration files read: %s",
232231
", ".join(str(s) for s in settings.read_from) if settings.read_from else "None",
233232
)
234233

234+
return logger
235+
235236

236237
def main(sys_args, when=None, settings=None):
237238
if "--pdb" in sys_args: # pragma: no cover
@@ -258,7 +259,7 @@ def main(sys_args, when=None, settings=None):
258259
parser = get_parser(settings)
259260
args = parser.parse_args(sys_args)
260261

261-
log_config(args.verbosity, settings)
262+
logger = log_config(args.verbosity, settings)
262263
logger.debug(args)
263264
if args.help:
264265
parser.print_help()

src/when/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .db import client
1414
from .lunar import lunar_phase
1515

16-
logger = logging.getLogger(__name__)
16+
logger = utils.logger()
1717

1818

1919
def holidays(settings, co="US", ts=None):

0 commit comments

Comments
 (0)