Time with Python: Automations in Personal Use

The 4th Go-Around

print(“

As any good teacher who finds lifelong learning fulfilling, I seek the next skill to satiate my dopamine craving. Adapting and uncovering newfound tools is like discovering the Temple of Doom. Adventure, danger, and uncovering something from deep within. 

Even though “for x in list” held up the first three attempts, I discovered a hack for this fourth round. Well, two hacks! Claude AI can act as a solid guide. The second is actively problem-solving real-world problems. I’ll give you three examples. The fourth attempt is important because I want to prove to myself that I can overcome challenges, and I have found myself repeatedly interested in learning Python. Watch out dictionaries, tuples (unchangeable lists), and multi-variable functions!

Case Study 1: Cabin Dues for Cousin

“Nick, I need help figuring out who owes what for staying at the cabin this week,” Garrett asks. His headset is on, as he works remotely from my parents’ dining room table.

“Don’t worry, cuz! I’ll make this a coding exercise,” I reply, opening up my laptop.

A spreadsheet may have been the quicker option, but instead I took the opportunity to spend an hour and a half learning about dictionaries and loops within loops. Those were also the most difficult parts to fathom.

A dictionary holds keys and values together in curly brackets. This code required three dictionaries: the schedule, which included the days and who was sleeping over; owed to track how much each person owes; and nights_stayed, noting how many nights each person stayed. Garrett laid out the schedule. The other dictionaries began empty.

The second tricky part related to previous attempts. Look at all those variables, especially the ones that are similar (occupant, occupants (a tuple), people_there, people, person). Honestly, I thought I wasn’t going to make it through without asking Claude to simply fill in the code for me. Yet, we persevered. After Claude provided a lesson on dictionaries that included a sample code, we uncoded the variables here. In the for loops (“for day in schedule” and “for person in people_there”), we figured out the information that went into the two empty dictionaries. Once we gathered the data, we could print out who owed what, based on how many nights they stayed and the number of people present on those nights (that’s the len part).

It takes me a few minutes and some intensive study to remind myself how this script works. I’m proud that I didn’t go the easy route and have Claude build it for me. This script entailed learning about several different features in Python employed in a real-world case. Problem: who owes what? Solution: this code. Changing just the first few variables makes this code reusable.

Garrett ended up using this when he texted folks to contribute. 

Case Study 2: RSS News Feed

I don’t focus on the news too much these days. It’s full of rubbish and gunk. Still, as a student of political science and a teacher of current events, I’ve got to stay somewhat up to date. This code replaced scrolling through Apple News and other individual organizations. One click and I’m provided with five headlines per feed. I can add more news links as long as they have an RSS feed. I had tried using AP News and Reuters, but their feeds didn’t exist. 

Here’s some of the news for today, August 18th:

Compare this code to that of the first example. Much shorter. Also somewhat easier to digest. I used another dictionary (“FEEDS”) and the “f” function. Without that one letter, the code would simply print (“\n=== {source} ===. The “/n”) also serves a function, creating a new line. In the first loop (for source, url in FEEDS.items()), we’re creating variables based on the FEEDS dictionary. The key receives “source”, and the value receives “url.” This in turn is parsed and eventually spit out into a clean list, as shown above.

I can see this code going further in the future, where I may create a function that runs it daily. Or, I may just run it weekly in my World Cultures class on a Friday. Each kid gets a link, reads the report, and shares it with us. I think I could also find some patterns and send that data to a spreadsheet to document. This script is neat because it simplifies the news and does it in about one second.

# Don’t tell the government.

Case Study 3: PDF Generator

I don’t use enough primary source questionnaires in class. If I want to create PDFs, AI can produce one-offs, but to keep a consistent format requires a template. Since I’m learning code, let’s do it in Python. This is not the easiest method, but it is usable. And it was fun to make.

This was the longest script I made by far at 72 lines. It was challenging because of its complexity and sheer number of lines. Claude introduced me to pdf. tools. The script features two functions (def ____). The first creates a footer for the page number and, in case I want to sell these on Teachers Pay Teachers, a copyright line. The toughest part was formatting, which required managing single lines, multi-lines, and keeping questions together. 

This is the main script. In a separate script, I have to “call” this function on each primary document, which includes questions and an answer key. Thus far, I’ve assembled the “Gettysburg Address” and the “Emancipation Proclamation.” Claude continued to provide dummy examples to illustrate key points like enumerate and pdf.cell vs pdf.multicell.

The scripts will design more primary document interactions for my students in a standardized format. All I have to do is replace the content and output a new PDF. This will aid students in understanding defining documents like the “Declaration of Independence” and the “Treaty of Versailles.”

Closing

Learning Python for the fourth time is like writing a story. I’m only limited by my imagination. As I trudge into the Temple of Doom and spy the ongoing ritual of blood and death, I know I’ll soon be caught up in its exciting loops in loops, hundreds of variables, and new libraries. 

“Thou shalt not leave!” A function screams. He holds my heart over a dictionary.

In a scene shaded crimson red, While Loops chant repeatedly. Does it ever end?!

# Wait! You gotta call a function before it acts.

“No!” I reply, tearing out of the restraints holding my limbs down. 

If there’s one thing I must do, it is pacing. Go too hard or fast, and I’ll burn out.

“)

Keeps the lights on around here. The overflow goes toward my rotating cast of addictions: reenacting, coding, reading, writing.


Discover more from Bucci Creates

Subscribe to get the latest posts sent to your email.

Published by Nick Bucci

Teacher Traveler Writer

Any thoughts on this?

Discover more from Bucci Creates

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Bucci Creates

Subscribe now to keep reading and get access to the full archive.

Continue reading