Wednesday, December 2, 2015

How do you get this stuff on twitter?

This is a common question.  If you follow one of my notification twitter accounts @WCAlerts or @NorCoAlerts, the first thing you realize is that everything is completely automated, unlike some of the other ones where some guy is cutting and pasting information in his spare time.  I will manually post if there is an ongoing incident and I happen to be at the computer, but 99% of my info is done without any user intervention.

So how do I do it.  The very short answer is this:
/usr/bin/perl /usr/local/bin/ttytter.pl -status=$msg -ssl

A less short answer is I use a program called TTYtter (http://www.floodgap.com/software/ttytter/).  Once you set it up, you can send a twitter post through the command line, with the $msg variable above being the actual post.  This is  done in a linux bash shell, so you either need to be running linux/Unix, or cygwin (https://www.cygwin.com/) under windows.  This should also work in MacOS 10, although I have never tried it.

Setting up TTYtter is actually pretty easy, however getting your data to a state where you can easily send it is not. 

My Backround
I went from working as a paid EMT back in the early 90's  the IT industry.  The last 15+ years I have dealt mainly with Unix/Linux systems.  Everything is done via a bash script.  These scripts are  very specific to my systems and the county websites, so it isn't something I can just hand someone and say go for it.They are adaptable and if another county comes online with a CAD, should be easily made to work with it.  I was able to get Northampton County up and running very quickly.  

Part 1 - CAD Posts
Sending out the CAD entries from Warren & Northampton Counties work pretty much the same way.  The scripts are a bit different due to differences in their formats, however they both basically work the same way.

Every couple of minutes I pull down all the CAD entries into a file (using lynx).  Then I do a series of of ugly unix commands (awk, sed, cut), and remove all the spaces and unwanted content.  The end result is everything in the CAD listed in a file which looks like this:

MVA W/INJURIES , RTE 57, MANSFIELD TWP
FALL 94 YOF, 73 W JOHNSTON ST, WASHINGTON BORO
CHEST PAIN 49 YOM, 130 POLKVILLE RD, KNOWLTON TWP
ELECTRICAL FIRE , 1041 RIDGE ST #33A, PHILLIPSBURG TO

The next step is I take each line of the file, compare it to an archive of all the previous posted entries.  If the entry does not exist, I post to twitter and add it to the archive.  If it is in the archive file, it moves on to the next line.  I keep about 75 of the newest entries to compare to.

That is really the high level explanation of how it works.  The next Blog post will cover the fire page mp3's (Part 2), and for those really bored, the history on how this whole thing developed (Part 3).


1 comment: