API for FMS twitter feed

I wrote this last night, and after seeing that it works today, figured I might share it.

This is a PHP API to grab the #FRCFMS Twitter feed, and parse it’s data in an easy-to-access way.

The file is http://servb.ath.cx:3445/~luke/1024/frcfms/frcfms.php, get the source at http://servb.ath.cx:3445/~luke/1024/frcfms/view.php?file=frcfms.php

Another file of interest is index.php, a sample use of this. adding ?team=XXXX will filter to only show a certain team. So, for example, I can see all of our team’s matches with http://servb.ath.cx:3445/~luke/1024/frcfms/index.php?team=1024

load_frcfms() returns an array of objects that have the

  • $date, $event, $type, $match, $red, $blue
  • $r1, $r2, $r3, $rBonus, $rPenalties, $rGoals, $rGoalPen
  • $b1, $b2, $b3, $bBonus, $bPenalties, $bGoals, $bGoalPen

sub-variables for you to access. r/b1-3 are the teams involved, red/blue are the final scores.

I’ll probably write up some real documentation eventually, but hopefully some of you find this useful.

Doesn’t twitter have it’s own API?

The only reason I say that is because I’ve done a lot of xlet programming (java applet for tru2way cable boxes), and one of the things I wrote was a twitter client.
I haven’t messed with it since… last summer… and I don’t intend to anymore.

Actually, come to think of it, I might tweak my program to do just that, so I have something to distract me at work these next few weeks :stuck_out_tongue:

I didn’t even think about using the Twitter feed like that, pretty sweet… thanks for the idea!

by the way, your frcfms_event() function would probably be better off as an associative array :wink: slightly more efficient, slightly neater.

I have also attempted this… mine isn’t currently set up as a distributable API, but more for personal/team use… however I do have it live on the web for all to use

the URL is http://fletch809.mine.nu/FRCFMS

I’m wide open to suggestions for it, and already have a list of features to add

I would also like to add that mine is stored in a mySQL database for future use as twitter’s API only allows you to read so many tweets at a time

I think so, but it was trivial to parse the RSS, the real benefit of my API is parsing of the special format of their posts into usable data.

That’s nifty, although, if I were to do something like that, I would take advantage of Google Reader’s cache to take a load off of our 300Mhz, 3.4GB server :slight_smile:

I also think that anyone using mine should set up a cron task to download/cache a copy of the RSS feed every minute or something, as sometimes it is unresponsive, which will throw a PHP error if it can’t open.

mine uses a cron task to run a python script every 30 minutes to parse the recent tweets(since the last recorded one), and is reading the XML version of the twitter API

I’ve updated mine to use a cache.
Check out `table.php’ in http://servb.ath.cx:3445/~luke/1024/frcfms/cached/
The cache is out of-date/missing entries, because I was testing it on my computer, which didn’t have constant internet, and now shell_exec is disabled on the server for security purposes, and it is needed to update the cache. Anyway, if it were enabled, it would update every minute on the minute.

Luke, Looks like you’re at the spot I was a week or so ago… I chose to switch my txt “cache” file to a mysql database for efficiency reasons

also, just out of curiosity, what do you need shell_exec for?

Luke, you finally stated to use mysql, I am shocked. oh and just to let you know it wouldn’t take any of the stress off of the servers because the SQL database is on serva as well, all servb is running is NFS so serva can get to it

I basically dump semi-parsed data to stdout so I can use simple UNIX utils to add it to the existing cache, via:

shell_exec("echo '".$data."' | cat - cache_file.txt | sort | uniq > cache_file.txt");
  1. no, I didn’t start useing MySQL. What gave you that impression?
  2. it would take less HDD space, and not have to check for updates every minute, because it is using HTTP to get google’s cache. Though, I didn’t do this, I did write my own cache.

interesting… you didn’t feel like using PHP’s built-in file system functions?

Bump

I’m from a fairly inept team, and personally I have little idea what this is about (I had to Google API). I’m trying to use this code to turn the Twitter feeds into a graphic output which we can have on a computer monitor in our pit.

Again, I have absolutely no idea what I’m doing. How does one implement these programs?