Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

timezones-cli

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timezones-cli - npm Package Compare versions

Comparing version
0.3.3
to
0.3.4
+2
entry_points.txt
[console_scripts]
tz = timezones_cli.main:cli

Sorry, the diff of this file is not supported yet

Metadata-Version: 2.1
Name: timezones-cli
Version: 0.3.4
Summary: Get local datetime from multiple timezones!
Home-page: https://github.com/yankeexe/timezones-cli
Author: Yankee Maharjan
License: MIT
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Description-Content-Type: text/markdown
License-File: LICENCE
Requires-Dist: click ==8.1.5
Requires-Dist: pycountry ==22.3.5
Requires-Dist: pytz
Requires-Dist: rich <=7.1.0
Requires-Dist: simple-term-menu ==1.6.1
Requires-Dist: tabulate ==0.9.0
Requires-Dist: thefuzz[speedup]
Requires-Dist: tzlocal ==2.1
Provides-Extra: dev
Requires-Dist: black <=20.8b1 ; extra == 'dev'
Requires-Dist: flake8 ; extra == 'dev'
Requires-Dist: freezegun ; extra == 'dev'
Requires-Dist: mypy ; extra == 'dev'
Requires-Dist: pre-commit ; extra == 'dev'
Requires-Dist: pytest >=6.2.5 ; extra == 'dev'
Requires-Dist: types-pytz ; extra == 'dev'
Requires-Dist: types-tabulate ; extra == 'dev'
Requires-Dist: types-tzlocal ; extra == 'dev'
<img src="https://i.imgur.com/ZebplfT.png" width="110" align="left"/><h1>Timezones CLI</h1>
<p><strong>CLI toolkit for timezones:zap:</strong></p>
<p>
<img src="https://img.shields.io/pypi/v/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/pyversions/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/l/timezones-cli?color=%2334D058" />
<img src="https://static.pepy.tech/badge/timezones-cli" />
</p>
<img src="https://i.imgur.com/JIt8tQN.png" width="500" />
## What can you do with `timezones-cli`? :sparkles:
- Search for date and time based on city, country, or timezones.
- Manage dashboard for timezones you frequently view.
- Get UTC date and time based on your local timezone or any timezones.
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Search for timezones](#search-for-timezones)
- [Add/save timezones](#addsave-timezones)
- [Remove timezones](#remove-timezones)
- [Show saved timezones](#show-saved-timezones)
- [Select individual timezones from saved](#select-individual-timezones-from-saved)
- [Get UTC time](#get-utc-time)
- [Run using Docker :whale:](#run-using-docker-whale)
- [Contributing](#contributing)
## Installation
```bash
$ pip3 install timezones-cli
```
To run this CLI using Docker, check [Run using Docker :whale:](#run-using-docker-whale).
> **NOTE:** [List of country codes or timezone names](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) :earth_asia:
> **Use `-t` flag to toggle 24 hours format.**
## Usage
### Search for timezones
Get time based on the entered timezone or country code
- using country code (either 2 or 3 letters):
```bash
$ tz search US
$ tz search USA
```
- using timezone:
```bash
$ tz search Asia/Kathmandu
```
- using fuzzy text: (example: Ireland)
```bash
$ tz search Irela
```
- using timezone shortcodes (--zone or -z flag):
```bash
$ tz search pst -z
$ tz search ist -z
$ tz search jst -z
$ tz search cest -z
$ tz search +0543 -z
$ tz search +05 -z
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/D2bcHG2.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Add/save timezones
Timezones added to the config file are treated as the default timezones which is triggered by the `tz show` command.
> file is stored at ~/.tz-cli
```bash
$ tz add "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/32XUBIP.gif" width="700" alt="demo of timezone cli add" />
</details>
---
### Remove timezones
There are two ways for removing timezones from the config file. Using the `--interactive` mode and passing the the `--name` flag.
```bash
$ tz remove -i
$ tz remove --name "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/q0lRtJt.gif" width="700" alt="demo of timezone cli remove" />
</details>
---
### Show saved timezones
```bash
$ tz show
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/s2Qq1Yb.gif" width="700" alt="demo of timezone cli show" />
</details>
---
### Select individual timezones from saved
```bash
$ tz select
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/VF91IZE.gif" width="700" alt="demo of timezone cli select" />
</details>
---
### Get UTC time
Get UTC time based on current system time.
> **tz utc --help**
```bash
$ tz utc
```
Get UTC time based on specified time and timezone.
```bash
$ tz utc <time> <timezone>
$ tz utc "11:45PM" "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/8hjy1XP.gif" width="500" alt="demo of timezone cli select" />
</details>
## Run using Docker :whale:
```bash
docker pull ghcr.io/yankeexe/timezones-cli:latest
```
Verify signature of the image: requires [cosign](https://docs.sigstore.dev/cosign/installation/).
```bash
COSIGN_EXPERIMENTAL=true cosign verify ghcr.io/yankeexe/timezones-cli:latest
```
Create a config file manually first.
```bash
$ touch ~/.tz-cli
$ docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli search us
```
For convenience you can add alias of the command to your shell config:
```bash
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.bashrc
$ source ~/.bashrc
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.zshrc
$ source ~/.zshrc
# Use alias to invoke timezones-cli
$ tz search Nepal
```
---
For local debugging: Use the `make run` command followed by the command you want to run against the `tz` binary.
```bash
$ make run cmd="get ist"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/t8RgJqg.png" width="500" alt="demo of timezone cli with Docker" />
</details>
## Contributing
For guidance on setting up a development environment and how to make a contribution to `timezones-cli`, see the [contributing guidelines](https://github.com/yankeexe/timezones-cli/blob/master/CONTRIBUTING.md).
timezones_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
timezones_cli/main.py,sha256=Pcto8dUuyJaznzrOSuI9vuAupfO6G_M9dhtys43RZjw,293
timezones_cli/commands/__init__.py,sha256=sBRmJNxjRPPYtoLz06-EwHyoF8gjIz6H1yzy28-uyyw,327
timezones_cli/commands/add.py,sha256=sLafNAOCY-dspeKdoMRTWuXknjL_pJDC2fVCsBDQRPQ,1642
timezones_cli/commands/remove.py,sha256=8KW4WTdsBccfsYmwG3TKWW9DU3yoAha5GyiyD27ckfk,866
timezones_cli/commands/search.py,sha256=1C03AK6P09ogZsp9_dxc_8cPnZivXI6aVw18dIKy5zU,1580
timezones_cli/commands/select.py,sha256=XdBYv4tnGO2w0RCxyhI_bkeHyd6WmDGgnLyGsw5whFQ,773
timezones_cli/commands/show.py,sha256=I3Kr2vPICNUSPjcXjQqSLvlOmxZgaGKtN3cYEha3Jt0,1105
timezones_cli/commands/utc.py,sha256=7cAfmdRIJH-x-eIRQvSgdm5oHi1GmJ_znsggZ5ZFjsU,1278
timezones_cli/utils/__init__.py,sha256=olc8eC5OXP1BBV_Ju8LlwAJYxaxOBqM5iZ0iO2iDjzA,9804
timezones_cli/utils/abbreviations.py,sha256=qzfkAxTUU4RLK1FI5-695e9kOCnDPy9HUxny_YwSEvM,3591
timezones_cli/utils/validators.py,sha256=XoXVZVfxqBl9ciFdiZrB74KRPuTPNV_OZnAwKqsLHxM,591
timezones_cli/utils/variables.py,sha256=xNszUkUZEpYJ5KiyRDVTFOizp4R48BTHTc3Ti3VbFQ4,154
timezones_cli-0.3.4.dist-info/LICENCE,sha256=QxxPFWRPuSpMyQOsnkhRNCggQecOBgDzcjCJi7_jRzc,1072
timezones_cli-0.3.4.dist-info/METADATA,sha256=VzC2akLPzM66C3tTW0noXe--i5Bgafk8JQt18w34xSA,6416
timezones_cli-0.3.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
timezones_cli-0.3.4.dist-info/entry_points.txt,sha256=V5GcPJsF4VG2Fx3jKC5oKAbzdJIWG4B_z4t5BN6_-OM,46
timezones_cli-0.3.4.dist-info/top_level.txt,sha256=0CtnPitRjrKBjiHJV5GlspUQRjdHuzE6wS0PC88ZJN0,14
timezones_cli-0.3.4.dist-info/RECORD,,
import click
class TzAbbrev(click.ParamType):
name = "Timezone Abbreviation"
def convert(self, value: str, param: str, ctx) -> str:
# validate timezone abbreviation length
if all(c not in value for c in ["+", "-"]) and ctx.params.get("zone"):
if 2 <= len(value) <= 4:
return value.upper()
else:
click.echo(ctx.command.get_help(ctx))
raise click.BadParameter(
"timezone code needs to be between 2 to 4 letters when using --zone flag"
)
return value
timezones_cli
Wheel-Version: 1.0
Generator: bdist_wheel (0.42.0)
Root-Is-Purelib: true
Tag: py3-none-any
+0
-1

@@ -6,3 +6,2 @@ """

from timezones_cli.commands.add import add
from timezones_cli.commands.get import get
from timezones_cli.commands.remove import remove

@@ -9,0 +8,0 @@ from timezones_cli.commands.search import search

@@ -10,31 +10,64 @@ import typing as t

query_handler,
tz_abbreviation_handler,
)
from timezones_cli.utils.validators import TzAbbrev
@click.command()
@click.argument("query")
@click.argument("query", type=TzAbbrev())
@click.option(
"--zone",
"-z",
help="define timezone short codes",
is_flag=True,
)
@click.option(
"--toggle",
"-t",
help="Toggle for 24 hours format",
type=bool,
default=False,
is_flag=True,
)
def search(query: str, toggle: bool):
def search(query: str, zone: bool, toggle: bool):
"""
Get time based on the entered timezone.
Get time based on the entered timezone or country code
$ tz search US
- using country code (either 2 or 3 letters):
$ tz search Africa
$ tz search US
$ tz search USA
- using timezone:
$ tz search Asia/Kathmandu
- using fuzzy text: (example: Ireland)
$ tz search Irela
- using timezone shortcodes (--zone or -z flag):
$ tz search pst -z
$ tz search ist -z
$ tz search jst -z
$ tz search cest -z
$ tz search +0545 -z
$ tz search +05 -z
"""
try:
result = query_handler(query)
if zone:
result = tz_abbreviation_handler(query)
else:
result = query_handler(query)
# If length is greater than one, show terminal menu.
if isinstance(result, t.List) and len(result) > 1:
entries = handle_interaction(result)
# If length is greater than one, show terminal menu.
if isinstance(result, t.List) and len(result) > 1:
result = handle_interaction(result)
return get_local_time(entries, toggle=toggle)
return get_local_time(result, query, toggle=toggle)
except LookupError:

@@ -44,3 +77,1 @@ return console.print(

)
return get_local_time(result, toggle=toggle)
""" Entrypoint of the CLI """
import click
from timezones_cli.commands import add, get, remove, search, select, show, utc
from timezones_cli.commands import add, remove, search, select, show, utc

@@ -13,3 +13,2 @@

cli.add_command(add)
cli.add_command(get)
cli.add_command(remove)

@@ -16,0 +15,0 @@ cli.add_command(search)

""" Utils for sub commands """
import os
import re
import sys
from collections import defaultdict
from datetime import datetime
from datetime import time as time_obj
from typing import Any, List, NamedTuple, Optional, Tuple, Union
from zoneinfo import ZoneInfo, available_timezones

@@ -13,2 +16,3 @@ import click

import tzlocal
from click.core import Command
from rich.console import Console

@@ -45,3 +49,3 @@ from simple_term_menu import TerminalMenu

config_file: str = variables.config_file
entry: Optional[str]
entry: List[str]
removed_timezones = []

@@ -141,6 +145,6 @@ add_prompt = "Use `tz add` to create and add timezone to your config file.:memo:"

name: str = getattr(country_data, "name", None)
alpha_2: str = getattr(country_data, "alpha_2", None)
alpha_3: str = getattr(country_data, "alpha_3", None)
official_name: str = getattr(country_data, "official_name", None)
name: Optional[str] = getattr(country_data, "name", None)
alpha_2: Optional[str] = getattr(country_data, "alpha_2", None)
alpha_3: Optional[str] = getattr(country_data, "alpha_3", None)
official_name: Optional[str] = getattr(country_data, "official_name", None)

@@ -219,3 +223,3 @@ return name, official_name, alpha_2, alpha_3

def print_help_msg(command):
def print_help_msg(command: Command):
"""

@@ -245,4 +249,4 @@ Get help message.

# Find integer value from the provided time string.
_minute = re.findall(r"-?\d+\.?\d*", minute)
_hour = re.findall(r"-?\d+\.?\d*", hour)
_minute: List[str] = re.findall(r"-?\d+\.?\d*", minute)
_hour: List[str] = re.findall(r"-?\d+\.?\d*", hour)

@@ -342,1 +346,12 @@ # Error if no integer value is provided for time.

return timezones
def tz_abbreviation_handler(query: str):
now = datetime.utcnow()
tz_abbrev = lambda tz: ZoneInfo(tz).tzname(now)
tz_map = defaultdict(list)
for tz in available_timezones():
tz_map[tz_abbrev(tz)].append(tz)
tz_map = {k: sorted(v) for k, v in tz_map.items()}
return [tz_map[query][0]]
Metadata-Version: 2.1
Name: timezones_cli
Version: 0.3.3
Summary: Get local datetime from multiple timezones!
Home-page: https://github.com/yankeexe/timezones-cli
Author: Yankee Maharjan
License: MIT
Description: <img src="https://i.imgur.com/ZebplfT.png" width="110" align="left"/><h1>Timezones CLI</h1>
<p><strong>CLI toolkit for timezones:zap:</strong></p>
<p>
<img src="https://img.shields.io/pypi/v/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/pyversions/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/l/timezones-cli?color=%2334D058" />
</p>
<img src="https://i.imgur.com/JIt8tQN.png" width="500" />
## What can you do with `timezones-cli`? :zap:
- Search for date and time based on city, country, or timezones.
- Manage dashboard for timezones you frequently view.
- Get UTC date and time based on your local timezone or any timezones.
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Search for local date time](#search-for-local-date-time)
- [Search based on timezone abbreviations](#search-based-on-timezone-abbreviations)
- [Add timezones](#add-timezones)
- [Remove timezones](#remove-timezones)
- [Show local datetime of all saved timezones](#show-local-datetime-of-all-saved-timezones)
- [Select a single timezone from defaults](#select-a-single-timezone-from-defaults)
- [Get UTC time](#get-utc-time)
- [Run using Docker :whale:](#run-using-docker-whale)
- [Contributing](#contributing)
## Installation
```bash
$ pip3 install timezones-cli
```
To run this CLI using Docker, check [Run using Docker :whale:](#run-using-docker-whale).
> **NOTE:** [List of country codes or timezone names](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) :earth_asia:
> **Use `-t` flag to toggle 24 hours format.**
## Usage
### Search for local date time
You can use short country code like 'AE', 'RU', 'US' and so on.
You can search via city like: 'Paris', 'London', 'Moscow', 'Chicago' and so on.
```bash
$ tz search "us"
$ tz search "Nepal"
$ tz search "Paris"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/D2bcHG2.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Search based on timezone abbreviations
```bash
$ tz get "pst"
$ tz get "ist"
$ tz get "est"
$ tz get "cst"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/2xNhV08.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Add timezones
Timezones added to the config file are treated as the default timezones which is triggered by the `tz show` command.
> file is stored at ~/.tz-cli
```bash
$ tz add "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/32XUBIP.gif" width="700" alt="demo of timezone cli add" />
</details>
---
### Remove timezones
There are two ways for removing timezones from the config file. Using the `--interactive` mode and passing the the `--name` flag.
```bash
$ tz remove -i
$ tz remove --name "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/q0lRtJt.gif" width="700" alt="demo of timezone cli remove" />
</details>
---
### Show local datetime of all saved timezones
```bash
$ tz show
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/s2Qq1Yb.gif" width="700" alt="demo of timezone cli show" />
</details>
---
### Select a single timezone from defaults
```bash
$ tz select
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/VF91IZE.gif" width="700" alt="demo of timezone cli select" />
</details>
---
### Get UTC time
Get UTC time based on current system time.
> **tz utc --help**
```bash
$ tz utc
```
Get UTC time based on specified time and timezone.
```bash
$ tz utc <time> <timezone>
$ tz utc "11:45PM" "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/8hjy1XP.gif" width="500" alt="demo of timezone cli select" />
</details>
## Run using Docker :whale:
```bash
docker pull ghcr.io/yankeexe/timezones-cli:latest
```
Verify signature of the image: requires [cosign](https://docs.sigstore.dev/cosign/installation/).
```bash
COSIGN_EXPERIMENTAL=true cosign verify ghcr.io/yankeexe/timezones-cli:latest
```
Create a config file manually first.
```bash
$ touch ~/.tz-cli
$ docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli search us
```
For convenience you can add alias of the command to your shell config:
```bash
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.bashrc
$ source ~/.bashrc
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.zshrc
$ source ~/.zshrc
# Use alias to invoke timezones-cli
$ tz search Nepal
```
---
For local debugging: Use the `make run` command followed by the command you want to run against the `tz` binary.
```bash
$ make run cmd="get ist"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/t8RgJqg.png" width="500" alt="demo of timezone cli with Docker" />
</details>
## Contributing
For guidance on setting up a development environment and how to make a contribution to `timezones-cli`, see the [contributing guidelines](https://github.com/yankeexe/timezones-cli/blob/master/CONTRIBUTING.md).
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Description-Content-Type: text/markdown
Provides-Extra: dev
<img src="https://i.imgur.com/ZebplfT.png" width="110" align="left"/><h1>Timezones CLI</h1>
<p><strong>CLI toolkit for timezones:zap:</strong></p>
<p>
<img src="https://img.shields.io/pypi/v/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/pyversions/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/l/timezones-cli?color=%2334D058" />
</p>
<img src="https://i.imgur.com/JIt8tQN.png" width="500" />
## What can you do with `timezones-cli`? :zap:
- Search for date and time based on city, country, or timezones.
- Manage dashboard for timezones you frequently view.
- Get UTC date and time based on your local timezone or any timezones.
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Search for local date time](#search-for-local-date-time)
- [Search based on timezone abbreviations](#search-based-on-timezone-abbreviations)
- [Add timezones](#add-timezones)
- [Remove timezones](#remove-timezones)
- [Show local datetime of all saved timezones](#show-local-datetime-of-all-saved-timezones)
- [Select a single timezone from defaults](#select-a-single-timezone-from-defaults)
- [Get UTC time](#get-utc-time)
- [Run using Docker :whale:](#run-using-docker-whale)
- [Contributing](#contributing)
## Installation
```bash
$ pip3 install timezones-cli
```
To run this CLI using Docker, check [Run using Docker :whale:](#run-using-docker-whale).
> **NOTE:** [List of country codes or timezone names](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) :earth_asia:
> **Use `-t` flag to toggle 24 hours format.**
## Usage
### Search for local date time
You can use short country code like 'AE', 'RU', 'US' and so on.
You can search via city like: 'Paris', 'London', 'Moscow', 'Chicago' and so on.
```bash
$ tz search "us"
$ tz search "Nepal"
$ tz search "Paris"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/D2bcHG2.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Search based on timezone abbreviations
```bash
$ tz get "pst"
$ tz get "ist"
$ tz get "est"
$ tz get "cst"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/2xNhV08.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Add timezones
Timezones added to the config file are treated as the default timezones which is triggered by the `tz show` command.
> file is stored at ~/.tz-cli
```bash
$ tz add "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/32XUBIP.gif" width="700" alt="demo of timezone cli add" />
</details>
---
### Remove timezones
There are two ways for removing timezones from the config file. Using the `--interactive` mode and passing the the `--name` flag.
```bash
$ tz remove -i
$ tz remove --name "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/q0lRtJt.gif" width="700" alt="demo of timezone cli remove" />
</details>
---
### Show local datetime of all saved timezones
```bash
$ tz show
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/s2Qq1Yb.gif" width="700" alt="demo of timezone cli show" />
</details>
---
### Select a single timezone from defaults
```bash
$ tz select
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/VF91IZE.gif" width="700" alt="demo of timezone cli select" />
</details>
---
### Get UTC time
Get UTC time based on current system time.
> **tz utc --help**
```bash
$ tz utc
```
Get UTC time based on specified time and timezone.
```bash
$ tz utc <time> <timezone>
$ tz utc "11:45PM" "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/8hjy1XP.gif" width="500" alt="demo of timezone cli select" />
</details>
## Run using Docker :whale:
```bash
docker pull ghcr.io/yankeexe/timezones-cli:latest
```
Verify signature of the image: requires [cosign](https://docs.sigstore.dev/cosign/installation/).
```bash
COSIGN_EXPERIMENTAL=true cosign verify ghcr.io/yankeexe/timezones-cli:latest
```
Create a config file manually first.
```bash
$ touch ~/.tz-cli
$ docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli search us
```
For convenience you can add alias of the command to your shell config:
```bash
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.bashrc
$ source ~/.bashrc
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.zshrc
$ source ~/.zshrc
# Use alias to invoke timezones-cli
$ tz search Nepal
```
---
For local debugging: Use the `make run` command followed by the command you want to run against the `tz` binary.
```bash
$ make run cmd="get ist"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/t8RgJqg.png" width="500" alt="demo of timezone cli with Docker" />
</details>
## Contributing
For guidance on setting up a development environment and how to make a contribution to `timezones-cli`, see the [contributing guidelines](https://github.com/yankeexe/timezones-cli/blob/master/CONTRIBUTING.md).
[isort]
profile = black
[flake8]
exclude = dist,build,venv
max-line-length = 120
[egg_info]
tag_build =
tag_date = 0
"""Package setup"""
import setuptools
with open("README.md", "r") as f:
long_description = f.read()
requirements = [
"click",
"tabulate",
"rich<=7.1.0",
"pycountry",
"pytz",
"simple-term-menu",
"tzlocal==2.1",
"thefuzz[speedup]",
"backports.zoneinfo",
]
# Development Requirements
requirements_dev = [
"pytest>=6.2.5",
"black<=20.8b1",
"pre-commit",
"mypy",
"freezegun",
"flake8",
]
setuptools.setup(
name="timezones_cli",
version="0.3.3",
author="Yankee Maharjan",
url="https://github.com/yankeexe/timezones-cli",
description="Get local datetime from multiple timezones!",
license="MIT",
packages=setuptools.find_packages(exclude=["dist", "build", "*.egg-info", "tests"]),
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=requirements,
extras_require={"dev": requirements_dev},
entry_points={"console_scripts": ["tz = timezones_cli.main:cli"]},
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Operating System :: OS Independent",
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
],
)
[console_scripts]
tz = timezones_cli.main:cli
Metadata-Version: 2.1
Name: timezones-cli
Version: 0.3.3
Summary: Get local datetime from multiple timezones!
Home-page: https://github.com/yankeexe/timezones-cli
Author: Yankee Maharjan
License: MIT
Description: <img src="https://i.imgur.com/ZebplfT.png" width="110" align="left"/><h1>Timezones CLI</h1>
<p><strong>CLI toolkit for timezones:zap:</strong></p>
<p>
<img src="https://img.shields.io/pypi/v/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/pyversions/timezones-cli?color=%2334D058" />
<img src="https://img.shields.io/pypi/l/timezones-cli?color=%2334D058" />
</p>
<img src="https://i.imgur.com/JIt8tQN.png" width="500" />
## What can you do with `timezones-cli`? :zap:
- Search for date and time based on city, country, or timezones.
- Manage dashboard for timezones you frequently view.
- Get UTC date and time based on your local timezone or any timezones.
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Search for local date time](#search-for-local-date-time)
- [Search based on timezone abbreviations](#search-based-on-timezone-abbreviations)
- [Add timezones](#add-timezones)
- [Remove timezones](#remove-timezones)
- [Show local datetime of all saved timezones](#show-local-datetime-of-all-saved-timezones)
- [Select a single timezone from defaults](#select-a-single-timezone-from-defaults)
- [Get UTC time](#get-utc-time)
- [Run using Docker :whale:](#run-using-docker-whale)
- [Contributing](#contributing)
## Installation
```bash
$ pip3 install timezones-cli
```
To run this CLI using Docker, check [Run using Docker :whale:](#run-using-docker-whale).
> **NOTE:** [List of country codes or timezone names](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) :earth_asia:
> **Use `-t` flag to toggle 24 hours format.**
## Usage
### Search for local date time
You can use short country code like 'AE', 'RU', 'US' and so on.
You can search via city like: 'Paris', 'London', 'Moscow', 'Chicago' and so on.
```bash
$ tz search "us"
$ tz search "Nepal"
$ tz search "Paris"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/D2bcHG2.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Search based on timezone abbreviations
```bash
$ tz get "pst"
$ tz get "ist"
$ tz get "est"
$ tz get "cst"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/2xNhV08.gif" width="700" alt="demo of timezone cli search" />
</details>
---
### Add timezones
Timezones added to the config file are treated as the default timezones which is triggered by the `tz show` command.
> file is stored at ~/.tz-cli
```bash
$ tz add "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/32XUBIP.gif" width="700" alt="demo of timezone cli add" />
</details>
---
### Remove timezones
There are two ways for removing timezones from the config file. Using the `--interactive` mode and passing the the `--name` flag.
```bash
$ tz remove -i
$ tz remove --name "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/q0lRtJt.gif" width="700" alt="demo of timezone cli remove" />
</details>
---
### Show local datetime of all saved timezones
```bash
$ tz show
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/s2Qq1Yb.gif" width="700" alt="demo of timezone cli show" />
</details>
---
### Select a single timezone from defaults
```bash
$ tz select
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/VF91IZE.gif" width="700" alt="demo of timezone cli select" />
</details>
---
### Get UTC time
Get UTC time based on current system time.
> **tz utc --help**
```bash
$ tz utc
```
Get UTC time based on specified time and timezone.
```bash
$ tz utc <time> <timezone>
$ tz utc "11:45PM" "Asia/Kathmandu"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/8hjy1XP.gif" width="500" alt="demo of timezone cli select" />
</details>
## Run using Docker :whale:
```bash
docker pull ghcr.io/yankeexe/timezones-cli:latest
```
Verify signature of the image: requires [cosign](https://docs.sigstore.dev/cosign/installation/).
```bash
COSIGN_EXPERIMENTAL=true cosign verify ghcr.io/yankeexe/timezones-cli:latest
```
Create a config file manually first.
```bash
$ touch ~/.tz-cli
$ docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli search us
```
For convenience you can add alias of the command to your shell config:
```bash
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.bashrc
$ source ~/.bashrc
$ echo "alias tz='docker run --rm -it -v ${HOME}/.tz-cli:/home/tz/.tz-cli ghcr.io/yankeexe/timezones-cli'" >> ~/.zshrc
$ source ~/.zshrc
# Use alias to invoke timezones-cli
$ tz search Nepal
```
---
For local debugging: Use the `make run` command followed by the command you want to run against the `tz` binary.
```bash
$ make run cmd="get ist"
```
<details><summary><strong>Demo</strong></summary>
<img src = "https://i.imgur.com/t8RgJqg.png" width="500" alt="demo of timezone cli with Docker" />
</details>
## Contributing
For guidance on setting up a development environment and how to make a contribution to `timezones-cli`, see the [contributing guidelines](https://github.com/yankeexe/timezones-cli/blob/master/CONTRIBUTING.md).
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Description-Content-Type: text/markdown
Provides-Extra: dev
backports.zoneinfo
click
pycountry
pytz
rich<=7.1.0
simple-term-menu
tabulate
thefuzz[speedup]
tzlocal==2.1
[dev]
black<=20.8b1
flake8
freezegun
mypy
pre-commit
pytest>=6.2.5
README.md
setup.cfg
setup.py
timezones_cli/__init__.py
timezones_cli/main.py
timezones_cli.egg-info/PKG-INFO
timezones_cli.egg-info/SOURCES.txt
timezones_cli.egg-info/dependency_links.txt
timezones_cli.egg-info/entry_points.txt
timezones_cli.egg-info/requires.txt
timezones_cli.egg-info/top_level.txt
timezones_cli/commands/__init__.py
timezones_cli/commands/add.py
timezones_cli/commands/get.py
timezones_cli/commands/remove.py
timezones_cli/commands/search.py
timezones_cli/commands/select.py
timezones_cli/commands/show.py
timezones_cli/commands/utc.py
timezones_cli/utils/__init__.py
timezones_cli/utils/abbreviations.py
timezones_cli/utils/variables.py
from collections import defaultdict
from datetime import datetime as dt
import click
from rich.console import Console
from timezones_cli.utils import get_local_time
try:
from zoneinfo import ZoneInfo, available_timezones
except ImportError:
from backports.zoneinfo import ZoneInfo, available_timezones
console = Console()
@click.command()
@click.argument("query")
@click.option(
"--toggle",
"-t",
help="Toggle for 24 hours format",
type=bool,
default=False,
is_flag=True,
)
def get(query: str, toggle: bool):
"""
Get timezone data based on timezone shortcodes.
$ tz get pst
$ tz get ist
$ tz get jst
"""
now = dt.utcnow()
tz_abbrev = lambda tz: ZoneInfo(tz).tzname(now)
tz_map = defaultdict(list)
for tz in available_timezones():
tz_map[tz_abbrev(tz)].append(tz)
tz_map = {k: sorted(v) for k, v in tz_map.items()}
try:
data = tz_map[query.upper()]
get_local_time([data[0]], query.upper(), toggle)
except KeyError:
console.print(
f"[bold red]:x: Could not find datetime for query: [green]{query}[/green][/bold red]"
)