Using Records: a Twitter Example

When I first started figuring out how to do Toolbox programming (and trust me, I am a rank amateur), one of the things I remember Mike Westerfield (of Byte Works fame) saying is that to do Toolbox programming, you had to use records and pointers.

“What in the name of Rennyo is a record?”

A record is like a variable on steroids. In ORCA/Pascal, it’s a “type”, meaning it’s a type of variable. What’s special about a record is that it allows grouping of several other types of variables, making it like a “super variable.” The example Mike gives is a deck of playing cards; each card has a number and a suit. To see how this would be declared in Pascal, the example goes:

type
card = record
s: suit;
v: value;
end;

Each card variable is a record, and that record has two of its own variables, s for the suit and v for the value. Presumably suit would be either spades, clubs, hearts, and diamonds, and value is between 1-13 (or, since not actually clear here, among 2-10 and Jack, Queen, King, and Ace).

Let’s use another example: Twitter. My guess is that if you’re on the Internet (which you pretty much have to be to read this), you’ve heard about Twitter by now (or you just go to this site and nowhere else). In any case, I’m continuing to try and finish up my Twitter NDA, aka IItter, which is really close to release. In doing so, I learned quite a bit about data that Twitter puts out for each “Tweet” (each individual posting to Twitter).

For instance, if we fetch some Tweets from the m.twitter.com server (the “mobile” version of Twitter, although I think this is essentially the same as we’d get from the non-mobile server), we see an individual Tweet’s raw XML would look like this:

<status>
<created_at>Mon Apr 06 09:31:02 +0000 2009</created_at>
<id>1461922309</id>
<text>Ms. Unreliable just came online. Is that time for me to go to bed?</text>
<source>web</source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
<in_reply_to_screen_name></in_reply_to_screen_name>
<user>
<id>1401261</id>
<name>Ryan Suenaga</name>
<screen_name>rsuenaga</screen_name>
<location>96744</location>
<description>Hawai'i's best known Apple II Geek and social worker</description>
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/91133166/rsp_normal.jpg</profile_image_url>
<url>http://uncommon-cents.net/</url>
<protected>false</protected>
<followers_count>588</followers_count>
<profile_background_color>1A1B1F</profile_background_color>
<profile_text_color>666666</profile_text_color>
<profile_link_color>2FC2EF</profile_link_color>
<profile_sidebar_fill_color>252429</profile_sidebar_fill_color>
<profile_sidebar_border_color>181A1E</profile_sidebar_border_color>
<friends_count>247</friends_count>
<created_at>Sun Mar 18 06:26:37 +0000 2007</created_at>
<favourites_count>46</favourites_count>
<utc_offset>-36000</utc_offset>
<time_zone>Hawaii</time_zone>
<profile_background_image_url>http://static.twitter.com/images/themes/theme9/bg.gif</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
<statuses_count>20632</statuses_count>
<notifications>false</notifications>
<following>true</following>
</user>
</status>

Now, that’s quite a bit of code! However, we may just want to look at a few of these elements–or at least, for IItter, I’m just looking at a few of these elements. All I’m interested in is the text of the Tweet, the screen name of whomever Tweeted, and the date and time it was created. So, we’re talking these three items from the Tweet above:

<text>Ms. Unreliable just came online. Is that time for me to go to bed?</text>
<screen_name>rsuenaga</screen_name>
<created_at>Sun Mar 18 06:26:37 +0000 2007</created_at>

And yes, I know this is not 2007, but that’s what the Twitter API returned just now!

Once I have those, I have the basis of the data I wish to display. I also know that the text of the Tweet is at most 140 characters; the created_at information is a fixed length of 30 characters (a lot like a standard Internet date and time string seen with, among other things, electronic mail); and we also know that the maximum length of a Twitter screen_name is 15 characters.

So, if we want to set up a record type to account for this information, we can do so like this:

type
twitter_record = record
text : pstring;
screen_name: pstring;
created_at: pstring;
end;

var
my_twitter_record: twitter_record;

We have declared a record type called twitter_record to suit our needs of grouping the text, screen_name, and created_at information together, then declared the variable my_twitter_record of the type twitter_record for our use in this program.

Since we know that all of the data returned are strings of text less than 255 characters in length, pstrings are quite useful here. With appropriate parsing, we end up setting our variables so that they have these values:

my_twitter_record.text
is ‘Ms. Unreliable just came online. Is that time for me to go to bed?

my_twitter_record.screen_name is ‘rsuenaga

and finally,

my_twitter_record.created_at is ‘Sun Mar 18 06:26:37 +0000 2007

So, there’s a quick bit on records. It’s going to take a bit more time to get IItter done (I was hoping while I was off but many other things also needed attending to).

16 Responses to “Using Records: a Twitter Example”

  1. ANDY Says:

    < blockquote >< a href=”http://pillspot.org/”>Pillspot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. No prescription pills. Order pills online< /a >

    Buy:Arimidex.Lumigan.Mega Hoodia.Retin-A.Accutane.Valtrex.Synthroid.Petcam (Metacam) Oral Suspension.Zovirax.Zyban.Actos.Human Growth Hormone.Prednisolone.Prevacid.Nexium.100% Pure Okinawan Coral Calcium.

  2. PHILIP Says:

    < blockquote >< a href=”http://medicamentspot.com/”>Medicamentspot.com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. No prescription pills. Buy pills online< /a >

    Buy:Zyban.Retin-A.Accutane.Mega Hoodia.Prevacid.Arimidex.Actos.Nexium.Prednisolone.Human Growth Hormone.Petcam (Metacam) Oral Suspension.100% Pure Okinawan Coral Calcium.Zovirax.Valtrex.Synthroid.Lumigan.

  3. Lights Says:

    350 3501 350/ http://BEDROOMPROPERTY.INFO/tag/Polar Lights 1 : Polar

    1

  4. Cologne Says:

    Privmsg.Php privmsg php/ http://02JEEPPARTS.US/tag/Cologne Inurl : Cologne

    Cologne

  5. 1 tamron 90mm/ Says:

    f/2.8 http://03GMCPARTS.US/tag/sp af90mm f/2.8 di 1 : af90mm

    af90mm

  6. 110 Sony cdx/ Says:

    GT http://BESTPARTSPLUS.INFO/tag/GT : GT

    GT

  7. 10 Says:

    00a amp power/ http://ACEHARDWAREE.INFO/tag/QSC MX 10 : 10

    00a amp power/

  8. af90mm Says:

    1 http://03GMCPARTS.US/tag/sp af90mm f/2.8 di 1 : 1 tamron 90mm/

    f/2.8

  9. r2 Says:

    7150 http://yhpyev2-xg.AWESOMEBABYCLOTHES.INFO/tag/r2 7150 R2/ : r2

    R2

  10. usb Says:

    Software http://wprosperitysaxmou.BEDROOMPROPERTY.INFO/tag/Modem Software to usb/ : Software

    to

  11. Slicer Says:

    slicer http://iblackhsn.copious-systems.com/tag/meat+Slicer+slicer/ : Slicer

    meat

  12. Buy Says:

    Laptop http://dtoshiba4er8.AACEHARDWARE.INFO/tag/Best+Buy+toshiba+Laptop/ : toshiba

    toshiba

  13. Kohl's Says:

    penny http://ypicoam-fu.AUTOPARTSVILLE.INFO/tag/Kohl’s+Penny+penny/ : penny

    Penny

  14. Jacks Says:

    jacks http://gfreezervx-pa.APTAUTOPARTS.INFO/tag/atwood+jacks+electric+Jacks/ : atwood

    Jacks

  15. rugs Says:

    symptoms http://mkitchenfbmnj.ABABYCLOTHES.INFO/tag/symptoms+Drug+rugs/ : Drug

    rugs

  16. box Says:

    song http://galbummfnp.AUTOSECTIONS.INFO/tag/song+storage+box/ : storage

    song

Leave a Reply

  • Buy me a beer!

    If you like my software, please consider donating with PayPal.