Los Angeles County Crashbot

Over winter break I created a twitter bot called @lacrashbot. It automatically tweets every injury-collision that occurred in Los Angeles County in 2014, and it does so exactly when each one happened. It’s depressing!

I did it using python. And I put the code on github. I thought I’d share how I did this (so this post is basically just the readme file). This is a tutorial for creating a twitter bot that reads a csv and tweets content based on a timestamp.

LA Crashbot

LA Crashbot is a Twitter Bot that posts crashes as they occurred. The idea is to help people better understand the frequency at which people crash. The data used is two years old, so the crashes are “real-time.” See it in action here.

Basic overview

  • Uses publically available data.
  • Decodes the values in the data, so that sentences can be constructed.
  • Construct narratives of each crash (that are under 140 characters).
  • Uses a Raspberry Pi to schedule and execute each tweet.
  • All the scripts are python. And you also need spreadsheet software, such as LibreOffice Calc or Excel.

Note that I’m an amateur pythonist. I used this project as a way to learn it. So do not use this project if you want to learn best practices.

If anyone wants to use these scripts as a starter kit for their own bots, feel free (The decoding and narrative scripts can be useful for other goals, as well). As long as you have the data (which is not included here), you can create something similar for your region, or for just pededstrian-involved crashes, or for just crashes that resulted in death, etc.


  • Python
  • These python modules: tweepy, time, csv, os, pandas, numpy (I think that’s all of them)
  • A computer that will stay on all the time


  • Get some data. For Los Angeles County I got raw SWITRS data from the CHP website.

  • Use the switrs-handling.py script to filter those collisions to suit your desires. In my case, I filtered them to only include injury collisions. This reduced the amount of collisions from 49023 to 25498 (in LA County, 2014).

  • In the new csv, clean up the dates. Right now, the timestamps look like this: time = 0000 date = 0101. We want them to look like: time = 00:00 date = Jan 01. So first you have to split the month from the day. In LibreOffice Calc, use Text to Columns. Then use the decode-month.py script to convert the two numbers t0 spelled out (to three letters) months; then insert that into your working csv. Then merge that field with the day field, to produce “Jan 01”. Next, format the time field to be four digits, with a colon in the middle. Use this: 00\:00 as the custom format option.

  • Decode the data. The values in the data are more machine-readable than human-readable. For example, collision severity is 1, 2, or 3. By decoding those, we convert the numbers into strings, such as “injured,” “severely injured,” “killed.” In decode.py I’m choosing which fields I’m (probably) going to use, and decoding them in ways that will simplify the narration process. That file also carries over some fields that didn’t need decoding. And it doesn’t carry over a whole bunch of fields that we don’t care about.

  • Create narratives from the decoded data. narrate.py has LOTS of if/else statements in it. I put this together after much trial and error. It will probably give you a headache to look at. And it will probably annoy people who actually know python. But it works. When you create your own narratives you’ll discover quirks in the data. This is where you iron out those quirks the best you can. I feel that I didn’t do a great job with the bicyclist section. I was hesitant to publish it as is. But ultimately I did so because I concluded that it’s better than how the data originally was. Neither were totally accurate; but this is more accurate.

  • Use the Date and Time fields to schedule the tweets. at-job-create.py is a script that creates another script, called at-job-deploy.py (not included). Make sure to read the comments in at-job-create.py that tell you the header to add to at-job-deploy.py after it’s been created. When at-job-deploy.py is run, it schedules the tweets for the entire span of the data. It does so using the at command. When a tweet is scheduled to occur, the at command runs the twitterbot.py script, which checks LACinjury2014_Narrate.csv (or whatever your file generated by narrate.py is called) for any narrative that occurs this very day and minute. Then twitterbot.py tweets it!

  • Make sure to put your Twitter app credentials in twitterbot.py (tutorial on setting that up). I left those fields blank here. In the future, I should move those credentials to a separate file that is imported into twitterbot.py, and is ignored by git.

  • Test beforehand! Just keep your twitter account private at first; make a csv with like five crashes; set the dates of them for five minutes from now; run at-job-create.py; then at-job-deploy.py; then wait five minutes to see if they post. Note that twitter doesn’t always like when your tweets have the exact same content as your other tweets. That’s why I included the timestamps in the narratives. Also, do some tests by just running twitterbot.py (because it’s easier to see errors when you run it yourself). Make sure you only run it when there’s a tweet with a timestamp of this very minute. Also, make sure to test this on the computer where you’ll be storing this stuff. In my case, I was ssh’ing into my Raspberry Pi.

How to be seen without seeming scene

This post is a bit of a follow-up to the one where I plastered my bike with reflective tape. I’ve since added green spoke lights. They took five minutes to install. I think they make me way more visible than standard front and rear lights because:

  1. They move. They’re on the spokes, and the spokes are always moving. Moving lights catches peoples’ attention.
  2. They’re green. We see red and white lights everywhere on the streets. But we see green ones way less often.
  3. They’re really bright. As you can see in the picture, they create an orb of light on the ground below the wheel.

Spoke lights

I got them from Amazon for $6. About a year ago I bought them from a seller on Etsy for $20. I thought he made them. They’re simple devices (string of 3M LEDs with a battery and a switch), and he made a video talking about his creation (plus you can’t resell stuff on etsy unless it’s vintage). But, I’m fairly sure he was just selling these RTGS brand ones with a big markup. Also, I followed his installation video and after a month both fell off and broke because they advised using two zip ties.

So! Make sure to attach them using FOUR (4) zip ties. I don’t have a picture. But just wrap two zip ties (next to one another) around the battery box. Then slip two zip ties under those two (perpendicular to the first two). Then wrap those two around your wheel hub. Tighten it. For the LED string, wrap it around one spoke a bunch of times, heading toward the wheel. Once it gets close to the wheel, turn and go around the perimeter. Wrap the string around every other spoke as you go.

This is a cheap and easy way to be WAY more visible while riding your bike. I’ve definitely noticed that drivers seem to spot me immediately. And it looks cool.

Bali High Soundtrack On Vinyl

Six years ago I posted the soundtrack to the 1981 surf movie, Bali High. To obtain this soundtrack, I transferred the VHS tape to DVD, then DVD to MP4, and then I extracted the audio. Needless to say, the quality wasn’t great (and I couldn’t exclude the narration). However, it’s a great soundtrack, and the posted garnered some interest. In fact, it caught the attention of the songwriter, Michael Sena! He was happy to see people still appreciating the soundtrack and new people were discovering it. I’m always concerned that someone will object to me posting their music on this site (though no one has), and it’s really nice when they’re stoked. I’m not making any money here – I’m just trying to spread the news – but I don’t want to contribute to bands losing sales. That’s why I only post music that’s long out of press, or, in this case, was never available as a stand-alone album.

Then, a year ago, Keith from Anthology Recordings (an imprint of Mexican Summer), contacted me. He discovered the Bali High soundtrack from here, loved it, and wanted to reissue it on vinyl as part of a surf film soundtrack series! Since Michael had left a couple comments on this blog, I had his email address. I passed it on to Keith. I wished him luck. A vinyl release of Bali High would be outstanding – beyond my expectations.

I checked Anthology’s site a couple months ago, and there it was! Bali High OST on vinyl, CD, and MP3!ARC016_Bali_High_front-500Keith sent it to me, and it’s beautiful! It’s a gatefold, double LP. There are liner notes by both Michael Sena and filmaker Stephen Spaulding, as well as some really great photos (including one of Sena at the time of the recording).

If you dig Bali High, pick this up! Forget that crappy recording I posted. The fresh, clean recording is SO much better! And the artist, and Anthology, deserve our support. They also released soundtracks to Morning of the Earth, Crystal Voyager, and Litmus. AND I just noticed that they made a Bali High t-shirt!


Use Reflective Tape to Make Your Bicycle More Visible at Night

My daily commute involves a four mile bike ride to a bus stop. Two miles of the route are on a four lane road with no bike lane and heavy car traffic. On my return trip, it’s often dark out. Feeling safe, and being safe, are my top priorities. I use bright front and rear flashing lights. I follow a “I’d rather be safe than right” mantra when interacting with other road users. And I ride at a safe pace (say, when car traffic is clogged, I don’t whiz between them and the parked cars at top speed). But I don’t wear a whole lot of reflective gear (just reflective bands around my ankles). In order to feel safe on my bike, it’s reassuring to know that people driving can see me well. In many parts of Los Angeles, people driving are not used to encountering many people bicycling, and they’re eager to get home after a long day of work. There’s little point in making them strain to see me.

So I took some cheap, easy measures to increase my visibility:

  • – Reflective tape on my bicycle frame
  • – Spoke lights

This post will only cover the reflective tape. Here’s my rig:

bicycle with reflective tape

In my opinion, the California Vehicle Code’s bicycle safety requirements are inadequate (white headlight, rear reflector, side reflectors on pedals). Even when fully complying, you may not be especially visible to others. And if you fail to include one of those elements, you’re basically invisible from some angles. In Los Angeles, Operation Firefly is a great program, wherein volunteers hang out on a corner and stop people who are bicycling without lights. Then they give them a free set of lights! Great program. Lights can be expensive; they can be stolen; they can break. There are many reasons why people aren’t properly set up with gear.

Luckily, you don’t need special bicycle gear or expensive technology to add more reflective material. Just buy a roll of 3M Scotchlite reflective tape, and get creative! Now, my bike isn’t fancy, and so I have no qualms about covering it with tape. If you do, you can cut the strips into really small shapes and place them discretely on the bike. And you can buy colors that match your bike. The cool thing about reflective tape is that it only works when a light is shining directly on it. Otherwise it looks like normal tape, and can blend in fairly well.

I bought a roll of 1 inch x 20 feet 8830 Silver Marking Film – 3M™ Scotchlite™ Reflective Material. I got it on Ebay. And I used probably 3/5 of the roll. The image above shows how my bike looks in daylight, and how it looks with a light reflected on it. Remarkable difference. As you can tell, I covered much of the frame. I tried to get all angles, and I added some to the pedal crank so that a moving part is reflective. As far as I can tell, other road users are well aware of me.

If you want to get more creative, you can cut the tape into interesting shapes. Some bicycle part manufacturers already sell small reflective stickers in shapes. But a set of stickers is much more costly than a roll of tape from ebay. Perhaps Operation Firefly, or another safety program, can start giving away a few feet of reflective tape. It could also be popular at school-based bicycle safety programs.

SketchUp Assignment

I thought I’d share an assignment I completed last quarter. Over the course of the quarter I went out to the site (a real block, in South Pasadena), measured everything, and created various architectural drafts (by hand). Then I modeled it using SketchUp. Then I added “enhancements.” In these views, you can see the things I added: pedestrian-activated crosswalk; bike corral; wayfinding sign; parklet; bike rack; etc. I put a lot in there, mostly as an exercise.

Click each image to see them larger.

It’s a nice street, with locally-owned shops, and trees, benches, and nearby amenities (library, farmer’s market, light rail station). My goals were to improve safety for people crossing the street, and to remove some of the free curb parking to allow better use of the space (there’s a huge parking lot half a block away).

I really enjoyed using SketchUp. I used a few third-party sprites: trees and plants; trashcan; bicycles, crosswalk signal; people; cars. But everything else I created myself (including the wayfinding sign, sandwich board, and railing). The third-party sprites bogged down the program. Otherwise, it was a joy to use. I occasionally have anal retentive behavior, and SketchUp really brought it out. There were a few points where I tried to cut corners and, say, not measure the width of a door on a building on the far end of the view, but I just couldn’t do it. Everything had to be perfect.

(If I could change one thing – which I can, of course! – I would remove the black border around the crosswalk.)

Pinball Map API Tutorial

When I’m figuring out how to add features to websites, the chances are strong that someone else has already accomplished my goal. And, since programmers seem like really giving people, they’ve probably posted a tutorial on how to do it. I rely enormously on those tutorials.

So, in that spirit, I wrote a little tutorial on the Pinball Map Blog, called, “Using the Pinball Map API to list machines on your website.” The audience for this tutorial is micro – limited to businesses that have pinball machines and want to tell site visitors their current line-up. But it’s a nice example of “set it and forget it” programming. I don’t think anyone’s used it aside from me. But maybe someday someone will.


A couple new comics

I drew a few comics about a year ago, but then forgot to upload them to tiny mix tapes. But now I have, and they’re appearing on the site every few weeks. Here’s the latest. And there are a couple more in the pipeline.

I haven’t been drawing a whole lot lately, though I’ve been trying to work on some short illustrated stories. Overall, I’m out of the groove.