BrentButler.com
Blog, etc. Weather Cubs Drumline
Thursday, April 12th, 2018
« Saturday, November 25th, 2017 All of April 2018 Friday, April 27th, 2018 »
Blog Entry Posted at 05:59:58 PM CDT
I Made a Twitter Bot
I Made a Twitter Bot (102.29 KB)
I made a Twitter bot on April 1st. It's garnered about as many followers in 11 days that my personal Twitter account has in 10 years.

Perhaps I should back up a few steps.

On Thursday, September 9, 1965, the Chicago Cubs and Los Angeles Dodgers played a night game in front of 29,139 fans at Dodger Stadium in Los Angeles. The Cubs featured three future Hall-of-Famers in their lineup that day: Billy Williams, Ron Santo, and Ernie Banks. Their starting pitcher, Bob Hendley, would only allow three on base all day, one each by hit, walk and error. Nonetheless, they were no match for fellow future Hall-of-Famer, Sandy Koufax. Needing only 113 pitches and 103 minutes, he struck out 14 and sat down all 27 Cubs batters that day, thus pitching the 8th-ever perfect game in Major League Baseball history.

The next day, the Cubs traveled to San Francisco to face the Giants. In the top of the 3rd, Billy Williams singled, thus starting a historic hitting streak. That was the first of 7,920 consecutive regular season games in which the Cubs got at least one hit. This Streak (The Streak™) nearly lasted 50 years. It's the longest such streak in Major League Baseball history. The Oakland Athletics have the current longest-streak (4,059 games as of today). It'll take the A's at least 23 years to tie the Cubs' record.

A lot happened during The Streak™, of course, but for the purposes of this story, I'll focus only on three points:

  • Twitter was founded on March 21, 2006, or 6,369 games into The Streak™
  • I set up my own Twitter account on March 27, 2007, or 6,531 games into The Streak™
  • The Cubs No-Hit Streak account debuted on June 4th, 2012, noting game number 7,393 of The Streak™

In addition to some good-natured, Cubs-fan Tweets along the way, the account has detailed just about every Streak-extender each game since getting started, including running a contest at one point having folks guess who'd extend The Streak™ each day.

Alas, The Streak™ did eventually end. On July 25, 2015, Cole Hamels no-hit the Chicago Cubs. I was already a big fan of the account up to that point, but it was pretty special that day:

And then, finally…

Admittedly, the Cubs official account nailed it, too:

The insatiable optimism of being a Cubs fan literally came back with a vengeance the very next day:

The account started with #1 of a new Baby Streak that day, which later graduated to being a Toddler Streak. The Cubs would go on to end their 108-year World Series drought in 2016, of course, and @CubsNoHitStreak was along for that ride, too, offering these wonderful encapsulations of what it was like:

The account remained active throughout the 2017 season, including counting streak-extenders, yet as this season started, the following announcement was made:

Looking for these "The Streak Lives" Tweets each Cubs gameday has become part of being a Cubs fan; watching the Cubs throughout the season would feel incomplete without it. I decided to look into whether I could help out.

Thanks to my Cubs page, I already utilize quite a bit of information from Major League Baseball. They have a lot of information out there, the vast majority of which I ignore out of a lack of use for it. However, once this announcement was made, I delved into those data feeds a bit more to see what might be possible. Sure enough, I found that there's a separate feed for each game that details every at-bat, down to each pitch. They're even nice enough to identify the result of each at-bat with values like Popout, Lineout, Strikeout, or more important for my use, Single, Double, etc. I found my chance and got to work.

Over the following weekend, I fiddled with some coding and those data feeds to see if I could programmatically identify the first hit of a game. I could. I went back through old @CubsNoHitStreak tweets to identify the exact format of each "Streak Extender" tweet. I loaded up a couple of modules to get me the ordinal for the inning (turn 1 into first, 2 into second, etc.), and a few other little odds and ends, plus quite a bit of error-checking. On April 1st, I set up the @CubsNHS_Bot account and had my script post a few recent streak-extender notices, including that day's a few hours after the fact. On April 2nd, the first fully-automated Tweet went out:

I'd let @CubsNoHitStreak know what I was up to ahead and of time and, after letting him know that the bot was running, he gave me a nice shoutout:

Over the next few days, I made some additional updates behind the scenes that'll allow the bot to detail Playoff Streak extenders. Barring changes by Major League Baseball – which are always possible with undocumented APIs – and various baseball anomalies (changes by the Official Scorer, on-field challenges overturning the first hit, games being rained-out before the end of the fifth inning and the game is "official," which is a situation that happened on August 3rd, 2015) this account is now on autopilot.

That said, since launching it, I've been doing all I can to monitor the start of Cubs games to see if the script runs, runs correctly, posts correctly, and has the correct information. It's batting 1.000 thus far.

One thing I didn't write into the script: what to do if the Cubs are no-hit again. They're not due to suffer another no-hitter for another 7,519 games (at least 46 years), so I've got time.

Lastly, I do want to extend a thank you to Jimmy Greenfield, who operates @CubsNoHitStreak. For me at least, his account adds a wonderful new layer of entertainment to being a Cubs fan. Give it a follow if you're interested, or better yet, buy the guy's book. He wrote "100 Things Cubs Fans Should Know & Do Before They Die," which he had to (got to?) update after the World Series win (I have a pre-2016 copy).

Go Cubs.

Quick Navigation
April 2018
SMTWTFS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
Content Types
Videos
Last: 10/07/24
Foursquare
Last: 10/15/23
Twitter
Last: 04/13/23
Blog
Last: 04/12/18
Pictures
Last: 08/21/17
Jokes
Last: 05/18/09
Restore All Content Types
« Saturday, November 25th, 2017 All of April 2018 Friday, April 27th, 2018 »
Currently in Des Moines:
Mostly Clear, 41°
©2000-2024 BrentButler.com.
Слава Україні! Героям слава!
6:29:18 AM CST
Friday, November 8th, 2024

Twitter

Bluesky

Mastodon

Threads

Facebook

Instagram

Twitch

YouTube

LinkedIn