Memorization With Python and Notifications

I’ve been struggling to allocate time and patience to a particularly dull theory-only module I’m currently taking. So, I’ve devised a “lifehack” to help manage my attention while keeping an eye on notes and aiding memorization. This method allows me to carry on with normal activities as I subtly reinforce learning.

Imagine a tool that periodically displays module definitions on your screen, helping you memorize them over time. Here’s how I did it using a simple Python script.

Python Script

This script grabs definitions from a text file and displays them in pop-up notifications. The idea is that you’ll gradually memorize the content through repeated subtle exposure.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, os, subprocess
from time import sleep

quotes = []
glossary = "glossary-boring-module.txt"  # <------- REPLACE PATH HERE
MAX_LENGTH = 120

def sendmessage(message):
    subprocess.Popen(['notify-send', message])
    return

def shortenedQuotes():
    global quotes
    new_array = []
    for quote in quotes:
        for i in range(0, len(quote), MAX_LENGTH):
            new_array.append(quote[i:i + MAX_LENGTH])
    return new_array

def getListOfQuotes():
    global glossary, quotes
    if os.stat(glossary).st_size != 0:
        with open(glossary, 'r') as file:
            quotes = [line.strip() for line in file]
        sendmessage(f"There are {len(quotes)} quotes before shortening. Recalculating...")
        sleep(20)
        quotes = shortenedQuotes()
        sendmessage(f"There are {len(quotes)} shortened quotes now.")
        sleep(20)
    else:
        sendmessage("OOPS! THE LIST IS EMPTY!")
        sys.exit()

def main():
    getListOfQuotes()
    if len(quotes) != 0:
        sendmessage(f"Displaying {len(quotes)} quotes")
        sleep(20)
        for quote in quotes:
            sendmessage(quote)
            sleep(20)
        sendmessage("No more quotes. Check the terminal to repeat or end the session.")
        if input("Enter 'y' to continue or any other key to exit: ") == 'y':
            main()
        else:
            sendmessage("Bye!")
            sys.exit()

if __name__ == '__main__':
    main()

How It Works

  1. Setup: Scrape the desired content and save it in a .txt file, specifying its path in the script.
  2. Run: Execute the script in a terminal. For Ubuntu users, the notifications appear as desktop pop-ups.
  3. Memorize: The repeated notifications help reinforce your memorization, especially for shorter pieces of information.

Handling Long Texts

The script automatically breaks down longer quotes into smaller segments, ensuring they fit nicely into notification pop-ups—no UI overflow or unreadable bubbles!


Feel free to adapt the code as you see fit. If you’re on a different OS, the basic logic remains useful; you’ll just need to adapt the notification method. Happy memorization and share your tweaks with the community!

Edit: I fixed a substring bug and added functionality to split strings based on a defined size—just place your definitions, one per line, in a file, and let the script handle the rest.