Using Replit to get our grandfather the daily baseball scores

JB

Jeff Burke

A few weeks ago, I was having dinner with my in-laws, when my grandfather-in-law came marching over. I knew something was wrong.

Mind you, he is not a complainer. He has a remarkable story. Born in Milwaukee. Military veteran. Worked in a meat-packing plant. Got into law school. Moved to California to teach at Stanford and practice law. Needless to say, when he has a problem, we listen.

“I have a real conundrum. The SF Chronicle stopped including the baseball scores in the daily paper.”

After 30+ years of checking scores in the SF Chronicle, they stopped sharing the daily MLB scores. Shame! Shame! Shame!

And it is a conundrum. He has no cable. I tried downloading the ESPN app to his phone, but finding his Apple password would have taken years, and once he asked me, “what’s an app?”, I knew we were in trouble.

He and I bond over my past life as a professional baseball player, and I love talking scores with him, so we needed a fix. I told him to give me a week.

Using Replit to solve this problem

An underrated aspect of learning to code is the mentality shift. You get more creative, and your relationship with computers changes. Most people have a passive relationship where they only think of computers solving problems based on the corpus of knowledge they have been taught.

But once you build your first piece of software, you start to recognize way more problems that computers can solve. The computer shifts from a preset box of applications to a malleable tool you can leverage. Ironically, learning to code solves and creates more problems for you at the same time.

This story is a clear example. Prior to coding, I would have spent hours trying to find the Apple password and educating a 90-year-old on how mobile apps work. With Replit, however, I knew I could build a custom application that solved this problem. So I did.

The approach to building

I have no coding background, but I have been learning over the past year or so. I built a Slack bot, and as Replit ships new features, the scope of projects I can build has expanded.

In this case, I knew Replit Scheduled Deployments could help me deliver the scores to my grandfather-in-law each day, but the two open questions were:

  • How would I get the MLB scores each day?
  • How would I send the scores to my grandfather-in-law?

Getting the daily MLB scores

I started by building a simple script that got the scores into my Repl. My first attempt was to scrape a public website with the scores. For those unfamiliar with webscraping, right-click this blog and click “inspect.”

Example of Inspecting HTML
Example of Inspecting HTML

A pane should open that shows a bunch of code (HTML) that builds the webpage. Using tools like BeautifulSoup, you can actually go to a webpage and pull down ALL of this text.

Example of web scraping HTML from Replit blog

Here’s a demo of Replit doing that start to finish in less than two minutes. Once you have all of that information, you can go through and parse the data. I did, however, run into issues:

  • Not every page wants you to scrape them
  • For the ones I could, it was challenging to isolate the scores within the HTML
  • Got the data in a format that would take a lot of work to reformat in an email

Before proceeding further, I decided to ask AI if I could just take a screenshot of the page:

Asking Replit AI how to take a screenshot
Asking Replit AI how to take a screenshot

Replit AI suggested Selenium, so I jumped into the Replit Selenium template. A Replit template comes with some preset configurations, so it should just “work” out-of-the-box.

From there, I used AI to generate the initial code. The one challenge was properly getting all of the scores in the screenshot. I modified the code with AI, and I was able to add some code that adjusted the page padding to properly capture the screenshot.

Screenshot of MLB box scores on Baseball Reference
Screenshot of MLB box scores on Baseball Reference

It’s not the cleanest, but it works!

Sending the scores daily

Now, I needed to get the scores to my grandfather-in-law. The obvious first step would be to send it via text, but the scores would be too small on the screen.

My second attempt was to use Zapier to handle sending the email, and my Repl would just send the screenshot to a webhook. This worked well, but I needed to buy Zapier’s $30/mo plan. I was not opposed to it, but that felt a bit like overkill for my use case.

Finally, a friend recommended Resend. Within <5 minutes of signing up, I was able to send my first email with Resend. The onboarding was super simple:

def send_email():
  resend.api_key = os.environ['RESEND_API_KEY_B']
  
  yesterday_date = datetime.date.today() - datetime.timedelta(days=1)
  yesterday_date_str = yesterday_date.strftime('%Y-%m-%d')
  
  screenshot_filename = f'screenshot_{yesterday_date_str}.png'
  
  f = open(
      os.path.join(os.path.dirname(__file__), screenshot_filename), "rb"
  ).read()
  
  params = {
      "from": "[email protected]",
      "to": ["[email protected]"],
      "subject": "Daily MLB Scores from Jeff",
      "html": "<strong>Open the attachment and print!</strong>",
      "headers": {
        "X-Entity-Ref-ID": "123456789"
      },
      "attachments": [{"filename": screenshot_filename, "content": list(f)}],
  }
  
  email = resend.Emails.send(params)

All I had to do was paste their code block in. I then used their documentation to test adding the screenshot, and BOOM! In minutes, the email was working.

Deployments pane on Replit
Deployments pane on Replit

Replit then made launching this application easy. I clicked Deploy, and there is a Scheduled option.

Example of using Replit Cron Scheduler

I just typed in to run this Repl “Send every day at 6am,” and Replit configured the machine to do that. Then click deploy… and like that… it’s done!!

The final result

With Replit + AI, I was able to whip up an application that solved my grandfather-in-law’s problem in just a day or two. Now, the script emails the scores to him at 6am each day before his coffee. He can quickly print them out.

Even if a simple no-code way existed, Replit makes it much more customizable and affordable. Not only can I adjust this however I want, but in total, this is costing me <$0.50 per month to run. Compare this to no-code tools that would cost +$10.

When he first tried it, he said, “Wow, this is terrific!” That’s the first time I have built software that someone else got genuine value out of.

What’s next

I wanted to build some add-ons to this. If I can more properly scrape and manipulate the data, I have thought about a few ideas:

  • Email directly to a printer, so it prints automatically for him
  • Add in the MLB standings to the daily report
  • Add other sports
  • Use an LLM to add highlight summaries for him to read

As I mentioned earlier, a key insight with learning to code is creativity. Coding is like lifting weights. It’s hard to get started, but the more you do it, the stronger you get. And the more you want to do it.

Now, I am searching for ways to not only solve problems in my daily life, but also, I want to find ways to add leverage. Save me time. Make me more productive. Make things more fun. That’s the goal.

If you have suggestions or want to follow along, reach out on X at @Jeff_Burke14.

More blog posts