Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Confused about twitterfetch example
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Confused about twitterfetch example

by nemesisrobot on Wed Apr 09, 2008 6:06 am

Okay I was looking through the twitterfetch example and came accross this piece of the code:

Code: Select all | TOGGLE FULL SIZE
    found = strstr(linebuffer, "entry-title entry-content");  //FIRST call here
    if (((int)found) != 0) {
      start = strstr(found, ">") + 1;
      end = strstr(found, "</p>");
      if ((start != 0) && (end != 0)) {
        //Serial.println("\n******Found first entry!*******");
        end[0] = 0;
        //Serial.print(start);
        // save the tweet so we can display it later
        strncpy(tweet, start, TWEETLEN);
        tweet[TWEETLEN-1] = 0;
      }
    }
   
    // next we look for a status ID (which should correspond to the previous tweet)e
    found = strstr(linebuffer, "<span id=\"status_actions_");  //SECOND call here


what confuses me are the two strstr function calls. If the first if statement is true and the code is executed then somewhere in linebuffer, there is a '0' character. Then we go on to continue to search through the string with the second strstr call. But won't it only go up to the wherever we inserted the '0' character into linebuffer? How is it that we are able to search past that point for "spand id=\...." and so on?
nemesisrobot
 
Posts: 25
Joined: Tue Jan 01, 2008 3:27 am

by nemesisrobot on Wed Apr 09, 2008 6:24 am

Well it looks like I found that answer to my own question. It seems that the avr-libc version of strstr doesn't compare '\0' characters :oops: .
Last edited by nemesisrobot on Wed Apr 09, 2008 9:43 pm, edited 1 time in total.
nemesisrobot
 
Posts: 25
Joined: Tue Jan 01, 2008 3:27 am

by adafruit on Wed Apr 09, 2008 12:40 pm

dont quite understand...where are we inserting a 0 into the line buffer?
it is unmodified!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by nemesisrobot on Wed Apr 09, 2008 9:39 pm

in the statement
Code: Select all | TOGGLE FULL SIZE
end[0] = 0;


end points to a character within linebuffer doesn't it?
nemesisrobot
 
Posts: 25
Joined: Tue Jan 01, 2008 3:27 am

by adafruit on Wed Apr 09, 2008 9:56 pm

thats after the strstr is done

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by nemesisrobot on Wed Apr 09, 2008 10:07 pm

but we make another call in
Code: Select all | TOGGLE FULL SIZE
found = strstr(linebuffer, "<span id=\"status_actions_");


but maybe I have it all wrong here? are we trying to find the tweet and status number within the same linebuffer or on seperate ones? So that on the first line, we'll find the tweet, the second strstr call evaluates to NULL so we move on and get the next like, where we'll find the status number?
nemesisrobot
 
Posts: 25
Joined: Tue Jan 01, 2008 3:27 am

by adafruit on Thu Apr 10, 2008 12:44 am

IIRC
you arent going to have both of those statements be true for the same line of text
the first one is specifically for the first twitter
the second is for remaining twitters
i suggest looking at the HTML of a twitter page for details

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by nemesisrobot on Thu Apr 10, 2008 10:20 pm

okay thanks that clears it up. it didn't occur to me that the status number and tweet might not be on the same line (in the html file)
nemesisrobot
 
Posts: 25
Joined: Tue Jan 01, 2008 3:27 am

by adafruit on Thu Apr 10, 2008 10:35 pm

i updated the code recently to use the xport library i wrote, which makes it a bit simpler to understand.
if you're planning to hack it, id suggest hacking that version!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Please be positive and constructive with your questions and comments.