A user on the project's Reddit thread commented

This is way too specific for a quarantine clock. Can you make it say "April-ish"?

Instead of displaying the day of the week, you can edit the code a little bit to make the code display the month instead of the date:

import time
import board
import busio
import digitalio
from adafruit_esp32spi import adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
from adafruit_pyportal import PyPortal
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label

    from secrets import secrets
except ImportError:
    print("""WiFi settings are kept in secrets.py, please add them there!
the secrets dictionary must contain 'ssid' and 'password' at a minimum""")

# Label colors

# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
background = None
# un-comment to set background image
# background = cwd+"/background.bmp"

# Descriptions of each hour
# https://github.com/mwfisher3/QuarantineClock/blob/master/today.html
time_names = ["midnight-ish", "late night", "late", "super late",
              "super early","really early","dawn","morning",
              "morning","mid-morning","mid-morning","late morning",
              "late afternoon","early evening","early evening","dusk-ish",
              "evening","evening","late evening","late evening"]

# Months of the year
months = ["January", "January", "February", "March", "April",
          "May", "June", "July", "August",
          "September", "October", "November", "December"]

# Dictionary of tm_mon and month name.
# note: tm_mon structure in CircuitPython ranges from [1,12]
months = {
    1: "January",
    2: "February",
    3: "March",
    4: "April",
    5: "May",
    6: "June",
    7: "July",
    8: "August",
    9: "September",
    10: "October",
    11: "November",
    12: "December"

esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
esp32_reset = digitalio.DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, debug=False)
requests.set_socket(socket, esp)

# initialize pyportal
pyportal = PyPortal(esp=esp,
                    default_bg = None)

# set pyportal's backlight brightness

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
    print("Firmware vers.", esp.firmware_version)
    print("MAC addr:", [hex(i) for i in esp.MAC_address])

print("Connecting to AP...")
while not esp.is_connected:
        esp.connect_AP(secrets['ssid'], secrets['password'])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)

# Set the font and preload letters
font_large = bitmap_font.load_font("/fonts/Helvetica-Bold-44.bdf")
font_small = bitmap_font.load_font("/fonts/Helvetica-Bold-24.bdf")
font_large.load_glyphs(b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ')
font_small.load_glyphs(b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()')

# Set up label for the month
label_month = label.Label(font_large, color=LABEL_DAY_COLOR, max_glyphs=200)
label_month.x = board.DISPLAY.width // 10
label_month.y = 80

# Set up label for the time
label_time = label.Label(font_small, color=LABEL_TIME_COLOR, max_glyphs=200)
label_time.x = board.DISPLAY.width // 3
label_time.y = 150

refresh_time = None
while True:
    # only query the network time every hour
    if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
            print("Getting new time from internet...")
            refresh_time = time.monotonic()
            # set the_time
            the_time = time.localtime()
        except (ValueError, RuntimeError) as e:
            print("Failed to get data, retrying\n", e)

    # convert tm_mon value to month name
    month = months[the_time.tm_mon]

    # determine and display how far we are in the month
    if 1 <= the_time.tm_mday <= 14:
        label_month.text = "Early %s-ish"%month
    elif 15 <= the_time.tm_mday <= 24:
        label_month.text = "Mid %s-ish"%month
        label_month.text = "Late %s-ish"%month

    # set the time label's text
    label_time.text = "({})".format(time_names[the_time.tm_hour])

    # update every minute

Code Walkthrough

When the code obtains the time from the internet, it stores the time returned in a specific structure type used to capture a date and a time called struct_time.

Getting new time from internet...
Getting time for timezone America/New_York
struct_time(tm_year=2020, tm_mon=4, tm_mday=23, tm_hour=9, tm_min=38, tm_sec=41, tm_wday=4, tm_yday=114, tm_isdst=None)

In the struct_time, tm_mon holds the the numerical representation of the month from 1 (January) to 12 (December). The updated code uses tm_mon to select an entry in the months dictionary

# convert tm_mon value to month name
month = months[the_time.tm_mon]

The conditional statement determines how far we are in the month: early month, in the middle of the month, or late in the month.

Then, the label is set to a string which is concatenates the time, month, and the phrase. i.e: "early + march + -ish"

# determine and display how far we are in the month
if 1 <= the_time.tm_mday <= 14:
  label_month.text = "Early %s-ish"%month
elif 15 <= the_time.tm_mday <= 24:
  label_month.text = "Mid %s-ish"%month
  label_month.text = "Late %s-ish"%month

This guide was first published on Apr 24, 2020. It was last updated on Apr 24, 2020.

This page (Quarantine Month Clock) was last updated on Mar 18, 2021.

Text editor powered by tinymce.