Skip to content

Instantly share code, notes, and snippets.

@danmaps
Last active May 15, 2022 16:57
Show Gist options
  • Save danmaps/2cafb695b85d93f055f0dd7a3a4dfc83 to your computer and use it in GitHub Desktop.
Save danmaps/2cafb695b85d93f055f0dd7a3a4dfc83 to your computer and use it in GitHub Desktop.
calendar as string like btwb
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]))
>>>πŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ”˜πŸ”˜πŸ”˜πŸ”˜|πŸ”˜πŸ”˜πŸ”˜πŸ”˜πŸ”˜πŸ”˜πŸ”˜|πŸ”˜βšͺβšͺβšͺβšͺβšͺβšͺ|βšͺβšͺβšͺβšͺβšͺβšͺβšͺ|βšͺβšͺβšͺ
```
@danmaps
Copy link
Author

danmaps commented May 15, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment