Last active
May 15, 2022 16:57
-
-
Save danmaps/2cafb695b85d93f055f0dd7a3a4dfc83 to your computer and use it in GitHub Desktop.
calendar as string like btwb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from calendar import monthrange, day_name | |
from datetime import datetime, date | |
def is_saturday(d): | |
return day_name[d.weekday()] == "Saturday" | |
def is_current_month(d): | |
return (d.year, d.month) == (datetime.now().year, datetime.now().month) | |
def parse_month(now=datetime.now(),highlight=[],chars=["π","π","βͺ","|"]): | |
highlighted = chars[0] | |
past = chars[1] | |
future = chars[2] | |
saturday = chars[3] | |
month_length = monthrange(now.year, now.month)[1] | |
out = "" | |
for day in range(1,month_length+1): | |
if day in highlight: | |
out += highlighted | |
else: | |
if is_current_month(now) and day > datetime.now().day: | |
out += future | |
else: | |
out+=past | |
if is_saturday(date(now.year,now.month,day)): | |
out += saturday | |
return(out) | |
print(parse_month()) | |
print(parse_month(highlight=[1,2,3])) | |
print(parse_month(highlight=[3,4,5,6],chars=["β","β","β"," "])) | |
print(parse_month(highlight=[3,4,5,6],chars=["β","β","β","\n"])) | |
print(parse_month(highlight=[x for x in range(30) if x%2==0])) | |
``` | |
print(parse_month(highlight=[1,2,3])) | |
>>>πππππππ|πππππππ|πβͺβͺβͺβͺβͺβͺ|βͺβͺβͺβͺβͺβͺβͺ|βͺβͺβͺ | |
``` |
Author
danmaps
commented
May 15, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment