Skip to content

Commit 227d477

Browse files
committed
Fixed issue with 2026 full year calendar. Also updated README.md.
1 parent 87d6227 commit 227d477

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.exe

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
11
# pythoncalendar
2-
cli calendar program for Windows written in Python
2+
Linux inspired cli calendar program brought to life on Windows with Python
3+
4+
## Preview
5+
*Requirement: any **Windows** version*
6+
7+
## Installation
8+
1. Open preferred console application.
9+
10+
2. Copy and paste the following:
11+
12+
```cmd
13+
cmd /v /c "IF EXIST %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\your-app.exe (set /p userinp=File already exists. Do you want to overwrite it? (y/n) ^& IF /I !userinp! == y curl -L -o %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\your-app.exe https://github.com/yourusername/yourrepository/releases/download/v1.0.0/your-app.exe) ELSE curl -L -o %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\your-app.exe https://github.com/yourusername/yourrepository/releases/download/v1.0.0/your-app.exe"
14+
```
15+
16+
3. Restart your console.
17+
18+
## Usage
19+
```cmd
20+
usage: cal [-h] [-y YEAR] [-m MONTH]
21+
22+
options:
23+
-h, --help show this help message and exit
24+
-y YEAR, --year YEAR
25+
-m MONTH, --month MONTH
26+
```
27+
### Examples
28+
* Displaying calendar of current date
29+
```cmd
30+
$ cal
31+
```
32+
33+
* Displaying 1997 full year calendar
34+
```cmd
35+
$ cal -y 1997
36+
```
37+
38+
* Displaying March calendar of current year
39+
```cmd
40+
$ cal -m March
41+
```
42+
43+
* Displaying calendar of March 1997
44+
```cmd
45+
$ cal -m March -y 1997
46+
```
47+
48+
## Update
49+
1. Run the installation command.
50+
51+
2. Type `y` and press enter when prompted the following:
52+
> Do you want to overwrite it? (y/n)
53+
54+
3. Restart your console.
55+
56+
57+
## License
58+
© 2023 digitalguy99. This project is licensed under the terms of the MIT license.

cal.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import calendar
22
import argparse
3+
import sys
34
from datetime import datetime
45

56
# Setting calendar start day
@@ -16,7 +17,11 @@
1617

1718
if args.month:
1819
if args.month not in [str(month_number) for month_number in list(range(1,13))]:
19-
cal_month = list(calendar.month_name).index(args.month)
20+
try:
21+
cal_month = list(calendar.month_name).index(args.month.capitalize())
22+
except:
23+
print(f"Enter appropriate month number or full name!\ncal: error: argument -m/--month: invalid entry: '{args.month}'")
24+
sys.exit()
2025
else:
2126
cal_month = int(args.month)
2227

@@ -29,6 +34,7 @@ def formatday(self, day, weekday, width):
2934
return f'\033[7m{day:>{width}}\033[m'
3035
return f'{day:>{width}}'
3136

37+
# Function to print month calendar
3238
def cal(month=None, year=None):
3339
if not month:
3440
month = datetime.now().month
@@ -37,6 +43,7 @@ def cal(month=None, year=None):
3743
cal = CustomCalendar(calendar.SUNDAY)
3844
print(cal.formatmonth(year, month))
3945

46+
# Function to print full year calendar
4047
def print_calendar(year: int):
4148
cal = calendar.TextCalendar(calendar.SUNDAY)
4249
today = datetime.now()
@@ -53,7 +60,7 @@ def print_calendar(year: int):
5360
if len(days) > 0:
5461
if i == 2 and len(days) < 7:
5562
days = [' '] * (7 - len(days)) + days
56-
elif i == len(month_str) - 2 and len(days) < 7:
63+
elif (i == len(month_str)-2) and (len(days) < 7):
5764
days += [' '] * (7 - len(days))
5865
for j in range(len(days)):
5966
if days[j].strip():
@@ -71,7 +78,13 @@ def print_calendar(year: int):
7178
quarter_str[-1] = ' '*(40 if s_no == 2 else 20) + quarter_str[-1]
7279
quarter_str.append(' ' + month_str[i])
7380
else:
74-
quarter_str[i] += ' ' + month_str[i]
81+
if i != (len(month_str)-1):
82+
quarter_str[i] += ' ' + month_str[i]
83+
else:
84+
if len(month_str) >= len(quarter_str):
85+
quarter_str[i] += ' ' + month_str[i]
86+
else:
87+
quarter_str[i] += 20*' ' + ' ' + month_str[i]
7588
print('\n'.join(quarter_str))
7689

7790
# Code to determine the calendar to print out

0 commit comments

Comments
 (0)