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.2.14
to
0.3.0
+2
-1
PKG-INFO
Metadata-Version: 2.1
Name: timezones_cli
Version: 0.2.14
Version: 0.3.0
Summary: Get local datetime from multiple timezones!

@@ -51,2 +51,3 @@ Home-page: https://github.com/yankeexe/timezones-cli

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.

@@ -53,0 +54,0 @@

@@ -44,2 +44,3 @@ <img src="https://i.imgur.com/ZebplfT.png" width="110" align="left"/><h1>Timezones CLI</h1>

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.

@@ -46,0 +47,0 @@

@@ -0,1 +1,8 @@

[isort]
profile = black
[flake8]
exclude = dist,build,venv
max-line-length = 120
[egg_info]

@@ -2,0 +9,0 @@ tag_build =

@@ -14,3 +14,3 @@ """Package setup"""

"simple-term-menu",
"tzlocal",
"tzlocal==2.1",
"thefuzz[speedup]",

@@ -25,2 +25,4 @@ ]

"mypy",
"freezegun",
"flake8",
]

@@ -30,3 +32,3 @@

name="timezones_cli",
version="0.2.14",
version="0.3.0",
author="Yankee Maharjan",

@@ -33,0 +35,0 @@ url="https://github.com/yankeexe/timezones-cli",

Metadata-Version: 2.1
Name: timezones-cli
Version: 0.2.14
Version: 0.3.0
Summary: Get local datetime from multiple timezones!

@@ -51,2 +51,3 @@ Home-page: https://github.com/yankeexe/timezones-cli

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.

@@ -53,0 +54,0 @@

@@ -8,8 +8,10 @@ click

thefuzz[speedup]
tzlocal
tzlocal==2.1
[dev]
black<=20.8b1
flake8
freezegun
mypy
pre-commit
pytest>=6.2.5
README.md
setup.cfg
setup.py

@@ -3,0 +4,0 @@ timezones_cli/__init__.py

"""
Exports for CLI commands.
"""
# flake8: noqa
from timezones_cli.commands.add import add

@@ -5,0 +6,0 @@ from timezones_cli.commands.get import get

@@ -9,17 +9,29 @@ """

from timezones_cli.utils import (check_config, console, validate_timezone,
variables)
from timezones_cli.utils import (
check_config,
console,
handle_interaction,
query_handler,
variables,
)
@click.command()
@click.argument("timezone")
def add(timezone: str):
@click.argument("query")
def add(query: str):
"""
Add timezone to the config file.
"""
validate_timezone(timezone)
added_timezones = []
existing_timezones = []
line_break = "\n"
timezones = query_handler(query)
if len(timezones) > 1:
timezones = handle_interaction(timezones)
config_file = variables.config_file
if not check_config():
with open(config_file, "w+") as newfile:
with open(config_file, "w+"):
pass

@@ -30,14 +42,22 @@

if timezone in data:
return console.print(
f"[bold green]Timezone already exists:[/bold green] [bold red]{timezone}:x:[/bold red]"
for timezone in timezones:
if timezone in data:
existing_timezones.append(f"[bold red]{timezone}:x:[/bold red]")
continue
file.read()
# Add to the end of the file.
file.write(f"{timezone}\n")
added_timezones.append(
f"[bold blue]{timezone}[/bold blue] :white_check_mark:"
)
# Read file
file.read()
if existing_timezones:
console.print(
f"[bold yellow]Timezone/s already exists:[/bold yellow]\n{line_break.join(existing_timezones)}"
)
# Add to the end of the file.
file.write(f"{timezone}\n")
if added_timezones:
console.print(
f"[bold green]New timezone added successfully:[/bold green] [bold blue]{timezone}[/bold blue] :white_check_mark:"
f"[bold green]New timezone/s added successfully:[/bold green]\n{line_break.join(added_timezones)}"
)

@@ -6,3 +6,2 @@ from collections import defaultdict

import click
from click.core import Option
from rich.console import Console

@@ -9,0 +8,0 @@

@@ -8,4 +8,8 @@ """

from timezones_cli.utils import (console, print_help_msg, remove_timezone,
validate_timezone)
from timezones_cli.utils import (
console,
print_help_msg,
remove_timezone,
validate_timezone,
)

@@ -12,0 +16,0 @@

import typing as t
import click
import pycountry
import pytz
from thefuzz import process
from timezones_cli.utils import (console, extract_fuzzy_country_data,
get_local_time, get_timezones,
handle_interaction, query_handler)
from timezones_cli.utils import (
console,
get_local_time,
handle_interaction,
query_handler,
)

@@ -33,10 +33,8 @@

result = query_handler(query)
payload: t.List = []
# If length is greater than one, show terminal menu.
if isinstance(result, t.List) and len(result) > 1:
entry = handle_interaction(result)
entries = handle_interaction(result)
payload.append(entry)
return get_local_time(payload, toggle=toggle)
return get_local_time(entries, toggle=toggle)
except LookupError:

@@ -43,0 +41,0 @@ return console.print(

@@ -6,4 +6,3 @@ """

from timezones_cli.utils import (console, get_local_time, handle_interaction,
variables)
from timezones_cli.utils import console, get_local_time, handle_interaction, variables

@@ -27,3 +26,2 @@

config_file = variables.config_file
entry = []

@@ -33,7 +31,7 @@ with open(config_file, "r+") as file:

if not len(data):
if not data:
return console.print("Config file contains no timezone:x:")
entry.append(handle_interaction(data))
entries = handle_interaction(data)
return get_local_time(entry, toggle=toggle)
return get_local_time(entries, toggle=toggle)

@@ -8,4 +8,9 @@ """

from timezones_cli.utils import (console, get_local_utc_time, get_utc_time,
validate_time, validate_timezone)
from timezones_cli.utils import (
console,
get_local_utc_time,
get_utc_time,
validate_time,
validate_timezone,
)

@@ -34,2 +39,3 @@

get_local_utc_time()
sys.exit()

@@ -36,0 +42,0 @@ try:

@@ -7,3 +7,2 @@ """ Utils for sub commands """

from datetime import time as time_obj
from datetime import timezone
from typing import Any, List, NamedTuple, Optional, Tuple, Union

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

import pytz
import tzlocal
from rich.console import Console

@@ -19,3 +19,2 @@ from simple_term_menu import TerminalMenu

from thefuzz import process
from tzlocal import get_localzone

@@ -49,2 +48,4 @@ from timezones_cli.utils import variables

entry: Optional[str]
removed_timezones = []
add_prompt = "Use `tz add` to create and add timezone to your config file.:memo:"

@@ -56,6 +57,3 @@ if not check_config():

)
console.print(
"Use `tz add` to create and add timezone to your config file.:memo:",
style="bold green",
)
console.print(add_prompt, style="bold green")
sys.exit()

@@ -66,3 +64,3 @@

if not len(data):
if not data:
console.print("Config file contains no timezone:x:", style="bold red")

@@ -72,13 +70,6 @@ sys.exit()

if interactive:
entry = handle_interaction(data)
entries = handle_interaction(data)
else:
entry = name
entries = [name]
# Check timezone existence in non-interactive mode.
if entry not in data:
console.print(
f"Timezone not found in your config file.:x:", style="bold red"
)
sys.exit()
# Clear file content.

@@ -88,18 +79,40 @@ file.seek(0)

for line in data:
if not line == entry:
file.write(f"{line}\n")
for entry in entries:
# Check timezone existence in non-interactive mode.
if entry not in data:
console.print(
f"Timezone {entry} not found in your config file.:x:",
style="bold red",
)
data.remove(entry)
removed_timezones.append(
f"[bold blue]{entry}[/bold blue] :white_check_mark:"
)
line_break = "\n"
console.print(
f"[bold green]Timezone removed:[bold green] [bold blue]{entry}[/bold blue] :white_check_mark:"
f"[bold green]Timezone removed:[bold green]\n{line_break.join(removed_timezones)}"
)
if not data:
console.print(
f"\n[bold red]No timezones in config.[/bold red]\n{add_prompt}",
style="bold green",
)
sys.exit(0)
def handle_interaction(data: List) -> str:
[file.write(f"{line}\n") for line in data]
def handle_interaction(data: List, multi_select=True) -> List[str]:
"""
Display interactive menu on the terminal.
"""
selections = []
try:
terminal_menu = TerminalMenu(data)
menu_entry_index: Optional[int] = terminal_menu.show()
terminal_menu = TerminalMenu(
data, multi_select=multi_select, show_multi_select_hint=multi_select
)
menu_entry_index: Optional[Tuple] = terminal_menu.show()

@@ -110,2 +123,6 @@ # Check for None value when user presses `esc` or `ctrl + c`

# if more than one timezone is selected.
for index in menu_entry_index:
selections.append(data[index])
except KeyboardInterrupt:

@@ -115,3 +132,3 @@ console.print("Exit:x:")

return data[menu_entry_index]
return selections

@@ -150,3 +167,3 @@

TIMEZONES.get(query, zone),
time_data.strftime(f"%B %Y %A %{hours}:%M:%S %p"),
time_data.strftime(f"%A, %B %d, %Y | %{hours}:%M:%S %p"),
)

@@ -294,3 +311,3 @@ )

utc_time = dt.strftime("%H:%M %p")
timezone = get_localzone().zone
timezone = tzlocal.get_localzone().zone

@@ -300,6 +317,5 @@ console.print(

)
sys.exit()
def match_fuzzy(query):
def match_fuzzy(query) -> List[str]:
timezones = []

@@ -310,2 +326,5 @@ all_timezones = list(pytz.all_timezones)

for match in matches:
if match[1] == 100:
return [match[0]]
if match[1] >= 75:

@@ -312,0 +331,0 @@ timezones.append(match[0])