Skip to content

Commit 786696c

Browse files
Notebook (#73)
* doc : notebook.ipynb added * doc : README.md updated * fix : minor edits * fix : run_clock function updated * doc : CHANGELOG.md updated * doc : notebook.ipynb updated * doc : notebook.ipynb meta-data updated * doc : notebook.ipynb break line updated * doc : options added
1 parent 68baa31 commit 786696c

File tree

4 files changed

+253
-72
lines changed

4 files changed

+253
-72
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88
### Added
9+
- `notebook.ipynb`
910
- Jupyter notebook support
1011
- `detect_environment` function
1112
### Changed
1213
- `clear_screen` function modified
1314
- `run_clock` function modified
15+
- `print_calendar` function modified
16+
- `README.md` updated
1417
## [1.2] - 2025-09-02
1518
### Added
1619
- `--offset-local` argument

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ clox --date-system=jalali --date-format=EU
211211

212212
</div>
213213

214+
## Try Clox Online!
215+
216+
Clox can be used online in interactive Jupyter Notebooks via the Binder or Colab services! Try it out now! :
217+
218+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/sepandhaghighi/clox/main)
219+
220+
[![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sepandhaghighi/clox/blob/main)
221+
222+
- Open `notebook.ipynb`
223+
214224
## Issues & Bug Reports
215225

216226
Just fill an issue and describe it. We'll check it ASAP!

clox/functions.py

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def show_date_formats_list(date_system: str = "GREGORIAN") -> None:
155155
"""
156156
datetime_lib = datetime
157157
example_year = 1990
158-
if date_system == "JALALI":
158+
if date_system.upper() == "JALALI":
159159
datetime_lib = jdatetime
160160
example_year = 1368
161161
print("Date formats list:\n")
@@ -176,7 +176,7 @@ def get_weekday_id(first_weekday: str, date_system: str = "GREGORIAN") -> int:
176176
if len(first_weekday) > 2:
177177
first_weekday_normalized = first_weekday_normalized[:2]
178178
weekdays = [x[:2] for x in WEEKDAYS_LIST]
179-
if date_system == "JALALI":
179+
if date_system.upper() == "JALALI":
180180
weekdays = weekdays[-2:] + weekdays[:-2]
181181
return weekdays.index(first_weekday_normalized)
182182

@@ -281,61 +281,64 @@ def run_clock(
281281
:param offset_local: manual offset for the local time
282282
:param offset_timezone: manual offset for the timezone
283283
"""
284-
detected_environment = detect_environment()
285-
datetime_lib = datetime
286-
if date_system.upper() == "JALALI":
287-
datetime_lib = jdatetime
288-
format_index = 0
289-
time_formats = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
290-
time_formats_local = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
291-
if vertical:
292-
time_formats = VERTICAL_TIME_12H_FORMATS if am_pm else VERTICAL_TIME_24H_FORMATS
293-
tz = None
294-
timezone_str = "Local"
295-
offset_main_timedelta = datetime_lib.timedelta(hours=offset_local)
296-
offset_local_timedelta = datetime.timedelta(hours=offset_local)
297-
if country is not None:
298-
timezone = pytz.country_timezones(country)[0].upper()
299-
if timezone is not None:
300-
timezone_str = timezone
301-
timezone_diff = get_timezone_difference(
302-
timezone=timezone,
303-
offset_local=offset_local,
304-
offset_timezone=offset_timezone)
305-
timezone_str += " ({timezone_diff})".format(timezone_diff=timezone_diff)
306-
tz = pytz.timezone(timezone)
307-
offset_main_timedelta = datetime_lib.timedelta(hours=offset_timezone)
308-
v_shift = max(0, v_shift)
309-
h_shift = max(0, h_shift)
310-
face = get_face(face)
311-
while True:
312-
clear_screen(detected_environment)
313-
print('\n' * v_shift, end='')
314-
print(" " * h_shift, end='')
315-
datetime_timezone = datetime_lib.datetime.now(tz=tz) + offset_main_timedelta
316-
time_timezone_str = datetime_timezone.strftime(time_formats[format_index])
317-
date_timezone_str = datetime_timezone.strftime(DATE_FORMATS_MAP[date_format.upper()])
318-
tprint(time_timezone_str, font=face, sep="\n" + " " * h_shift)
319-
if not hide_date:
320-
print(" " * h_shift, end='')
321-
print(date_timezone_str)
322-
if not hide_timezone:
284+
try:
285+
detected_environment = detect_environment()
286+
datetime_lib = datetime
287+
if date_system.upper() == "JALALI":
288+
datetime_lib = jdatetime
289+
format_index = 0
290+
time_formats = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
291+
time_formats_local = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
292+
if vertical:
293+
time_formats = VERTICAL_TIME_12H_FORMATS if am_pm else VERTICAL_TIME_24H_FORMATS
294+
tz = None
295+
timezone_str = "Local"
296+
offset_main_timedelta = datetime_lib.timedelta(hours=offset_local)
297+
offset_local_timedelta = datetime.timedelta(hours=offset_local)
298+
if country is not None:
299+
timezone = pytz.country_timezones(country)[0].upper()
300+
if timezone is not None:
301+
timezone_str = timezone
302+
timezone_diff = get_timezone_difference(
303+
timezone=timezone,
304+
offset_local=offset_local,
305+
offset_timezone=offset_timezone)
306+
timezone_str += " ({timezone_diff})".format(timezone_diff=timezone_diff)
307+
tz = pytz.timezone(timezone)
308+
offset_main_timedelta = datetime_lib.timedelta(hours=offset_timezone)
309+
v_shift = max(0, v_shift)
310+
h_shift = max(0, h_shift)
311+
face = get_face(face)
312+
while True:
313+
clear_screen(detected_environment)
314+
print('\n' * v_shift, end='')
323315
print(" " * h_shift, end='')
324-
print("Timezone: {timezone}".format(timezone=timezone_str))
325-
if offset_timezone != 0:
316+
datetime_timezone = datetime_lib.datetime.now(tz=tz) + offset_main_timedelta
317+
time_timezone_str = datetime_timezone.strftime(time_formats[format_index])
318+
date_timezone_str = datetime_timezone.strftime(DATE_FORMATS_MAP[date_format.upper()])
319+
tprint(time_timezone_str, font=face, sep="\n" + " " * h_shift)
320+
if not hide_date:
326321
print(" " * h_shift, end='')
327-
print(OFFSET_FORMAT.format(offset_type="Timezone", offset_value=offset_timezone))
328-
if timezone is not None:
329-
datetime_local = datetime.datetime.now() + offset_local_timedelta
330-
time_local_str = datetime_local.strftime(time_formats_local[format_index])
322+
print(date_timezone_str)
323+
if not hide_timezone:
331324
print(" " * h_shift, end='')
332-
print("Local Time: {local_time}".format(local_time=time_local_str))
333-
if offset_local != 0:
334-
print(" " * h_shift, end='')
335-
print(OFFSET_FORMAT.format(offset_type="Local", offset_value=offset_local))
336-
time.sleep(1)
337-
if not no_blink:
338-
format_index = int(not format_index)
325+
print("Timezone: {timezone}".format(timezone=timezone_str))
326+
if offset_timezone != 0:
327+
print(" " * h_shift, end='')
328+
print(OFFSET_FORMAT.format(offset_type="Timezone", offset_value=offset_timezone))
329+
if timezone is not None:
330+
datetime_local = datetime.datetime.now() + offset_local_timedelta
331+
time_local_str = datetime_local.strftime(time_formats_local[format_index])
332+
print(" " * h_shift, end='')
333+
print("Local Time: {local_time}".format(local_time=time_local_str))
334+
if offset_local != 0:
335+
print(" " * h_shift, end='')
336+
print(OFFSET_FORMAT.format(offset_type="Local", offset_value=offset_local))
337+
time.sleep(1)
338+
if not no_blink:
339+
format_index = int(not format_index)
340+
except (KeyboardInterrupt, EOFError):
341+
print(EXIT_MESSAGE)
339342

340343

341344
def main() -> None:
@@ -396,21 +399,18 @@ def main() -> None:
396399
offset_local=args.offset_local,
397400
offset_timezone=args.offset_timezone)
398401
else:
399-
try:
400-
run_clock(
401-
timezone=args.timezone,
402-
country=args.country,
403-
h_shift=args.h_shift,
404-
v_shift=args.v_shift,
405-
face=args.face,
406-
no_blink=args.no_blink,
407-
vertical=args.vertical,
408-
hide_date=args.hide_date,
409-
hide_timezone=args.hide_timezone,
410-
am_pm=args.am_pm,
411-
date_system=args.date_system,
412-
date_format=args.date_format,
413-
offset_local=args.offset_local,
414-
offset_timezone=args.offset_timezone)
415-
except (KeyboardInterrupt, EOFError):
416-
print(EXIT_MESSAGE)
402+
run_clock(
403+
timezone=args.timezone,
404+
country=args.country,
405+
h_shift=args.h_shift,
406+
v_shift=args.v_shift,
407+
face=args.face,
408+
no_blink=args.no_blink,
409+
vertical=args.vertical,
410+
hide_date=args.hide_date,
411+
hide_timezone=args.hide_timezone,
412+
am_pm=args.am_pm,
413+
date_system=args.date_system,
414+
date_format=args.date_format,
415+
offset_local=args.offset_local,
416+
offset_timezone=args.offset_timezone)

notebook.ipynb

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Clox\n",
8+
"----------------"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"## Environment Check"
16+
]
17+
},
18+
{
19+
"cell_type": "markdown",
20+
"metadata": {},
21+
"source": [
22+
"Checking that the notebook is running on Google Colab or not."
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"import sys\n",
32+
"try:\n",
33+
" import google.colab\n",
34+
" !{sys.executable} -m pip -q -q install clox\n",
35+
"except:\n",
36+
" pass"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"## Clock"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"from clox.functions import run_clock"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"clock_parameters = {\n",
62+
" \"timezone\": None, # https://github.com/sepandhaghighi/clox/blob/main/TIMEZONES.md\n",
63+
" \"country\": None, # https://github.com/sepandhaghighi/clox/blob/main/COUNTRIES.md\n",
64+
" \"v_shift\": 0,\n",
65+
" \"h_shift\": 0,\n",
66+
" \"face\": 1, # https://github.com/sepandhaghighi/clox/blob/main/FACES.md\n",
67+
" \"no_blink\": False,\n",
68+
" \"vertical\": False,\n",
69+
" \"hide_date\": False,\n",
70+
" \"hide_timezone\": False,\n",
71+
" \"am_pm\": False,\n",
72+
" \"date_system\": \"GREGORIAN\", # [\"GREGORIAN\", \"JALALI\"]\n",
73+
" \"date_format\": \"FULL\", # ['DASH', 'DMY', 'DOT', 'EU', 'EU-SHORT', 'FULL', 'ISO', 'MDY', 'US', 'US-SHORT', 'YMD']\n",
74+
" \"offset_local\": 0,\n",
75+
" \"offset_timezone\": 0\n",
76+
"}"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": null,
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"run_clock(**clock_parameters)"
86+
]
87+
},
88+
{
89+
"cell_type": "markdown",
90+
"metadata": {},
91+
"source": [
92+
"## Calendar"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": null,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"from clox.functions import print_calendar"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"metadata": {},
108+
"outputs": [],
109+
"source": [
110+
"calendar_parameters = {\n",
111+
" \"mode\": \"MONTH\", # [\"MONTH\", \"YEAR\"]\n",
112+
" \"timezone\": None, # https://github.com/sepandhaghighi/clox/blob/main/TIMEZONES.md\n",
113+
" \"country\": None, # https://github.com/sepandhaghighi/clox/blob/main/COUNTRIES.md\n",
114+
" \"v_shift\": 0,\n",
115+
" \"h_shift\": 0,\n",
116+
" \"date_system\": \"GREGORIAN\", # [\"GREGORIAN\", \"JALALI\"]\n",
117+
" \"date_format\": \"FULL\", # ['DASH', 'DMY', 'DOT', 'EU', 'EU-SHORT', 'FULL', 'ISO', 'MDY', 'US', 'US-SHORT', 'YMD']\n",
118+
" \"first_weekday\": \"MONDAY\", # [\"MONDAY\", \"TUESDAY\", \"WEDNESDAY\", \"THURSDAY\", \"FRIDAY\", \"SATURDAY\", \"SUNDAY\"]\n",
119+
" \"offset_local\": 0,\n",
120+
" \"offset_timezone\": 0\n",
121+
"}"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": null,
127+
"metadata": {},
128+
"outputs": [],
129+
"source": [
130+
"print_calendar(**calendar_parameters)"
131+
]
132+
}
133+
],
134+
"metadata": {
135+
"kernelspec": {
136+
"display_name": "Python 3",
137+
"language": "python",
138+
"name": "python3"
139+
},
140+
"language_info": {
141+
"codemirror_mode": {
142+
"name": "ipython",
143+
"version": 3
144+
},
145+
"file_extension": ".py",
146+
"mimetype": "text/x-python",
147+
"name": "python",
148+
"nbconvert_exporter": "python",
149+
"pygments_lexer": "ipython3",
150+
"version": "3.5.2"
151+
},
152+
"toc": {
153+
"base_numbering": 1,
154+
"nav_menu": {},
155+
"number_sections": false,
156+
"sideBar": true,
157+
"skip_h1_title": false,
158+
"title_cell": "Table of Contents",
159+
"title_sidebar": "Clox",
160+
"toc_cell": false,
161+
"toc_position": {},
162+
"toc_section_display": true,
163+
"toc_window_display": false
164+
}
165+
},
166+
"nbformat": 4,
167+
"nbformat_minor": 4
168+
}

0 commit comments

Comments
 (0)