Skip to content

Instantly share code, notes, and snippets.

@bitsandbooks
Created April 26, 2012 01:37
Show Gist options
  • Save bitsandbooks/2495080 to your computer and use it in GitHub Desktop.
Save bitsandbooks/2495080 to your computer and use it in GitHub Desktop.
VertiCal
#!/usr/bin/python
# VertiCal: A slim monthly calendar (that's perfect for GeekTool)
# by Rob Dumas
# Copyright (c) 2012 GNU Public License version 3.
# See http://www.gnu.org/licenses/licenses.html for details on this license.
import sys
import datetime
import calendar
# Get the current date and create our vertiCal.
today = datetime.date.today()
vertiCal = []
# Create a calendar object, whose weeks start on Sunday.
cal = calendar.Calendar(6)
# Set a variable for the day.
for i in cal.itermonthdays2( today.year, today.month ):
if i[1] == 0:
theday = "Mon"
elif i[1] == 1:
theday = "Tue"
elif i[1] == 2:
theday = "Wed"
elif i[1] == 3:
theday = "Thu"
elif i[1] == 4:
theday = "Fri"
elif i[1] == 5:
theday = "Sat"
elif i[1] == 6:
theday = "Sun"
else:
print "Error: Day of week is not between 0 and 6."
# Make sure the date is nonzero before appending to our list.
if i[0] != 0:
# ANSI codes:
# 'black': '0;30', 'bright gray': '0;37',
# 'blue': '0;34', 'white': '1;37',
# 'green': '0;32', 'bright blue': '1;34',
# 'cyan': '0;36', 'bright green': '1;32',
# 'red': '0;31', 'bright cyan': '1;36',
# 'purple': '0;35', 'bright red': '1;31',
# 'yellow': '0;33', 'bright purple': '1;35',
# 'dark gray': '1;30', 'bright yellow': '1;33',
# 'normal': '0'
startofline = "" # empty by default
default = '''\033[1;37m''' # white by default
highlighted = '''\033[0;33m''' # yellow
endofline = ''' \033[0m''' # return to normal at EOL
separator = ""
monthlen = len( today.strftime( "%B" ) )
if monthlen < 6: monthlen = 6
for d in range( monthlen ):
separator += "-"
if i[0] == today.day:
startofline = highlighted
spacer = " "
else:
startofline = default
spacer = " "
thestring = startofline + theday + spacer
# At this point, thestring should look something like:
# \033[1;37mMon (normal)
# \033[0;33mTue (highlighted)
# Add an extra space to the line if the date is a single digit.
if 1 <= i[0] <= 9: thestring += " "
# Add the date to thestring.
thestring += str(i[0]) + endofline
# At this point, thestring should look something like:
# \033[1;37mMon 9\033[0m (normal)
# \033[0;33mTue 10\033[0m (highlighted)
vertiCal.append(thestring)
# Print it all out.
print highlighted + today.strftime( "%B\n%Y" ) + endofline
print default + separator + endofline
for item in vertiCal: print item
@haincha
Copy link

haincha commented Mar 23, 2013

Thank you! This was really helpful.

@GitGoo70
Copy link

GitGoo70 commented Nov 4, 2023

Hi Rob, love this script, been using it for years. However I updated to MacOS Monterey and it stopped working, even though Geektool still functions, the script stopped working. Im running Python3 on Monterey. I tired changing the path to Python3 to no avail. Any help would be much appreciated. Perhaps I can buy you a beer, or a coffee via PayPal. Cheers!

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