Using XPath to get tweets excluding replies
While it’s not that common (so far I’ve only seen (Symphony)[http://symphony-cms.com/] use it), an XML/XSL/XPath system is extremely powerful and flexible.
Since Twitter provides a list of your tweets as an RSS feed, which is just a specialized XML file, you can apply this flexibility to that (within Symphony, at least).
The one thing that most annoys me about embedding my last Twitter post in my website is that replies, which are usually out of context, get embedded too. Using some complicated XPath, we can get rid of that.
The XPath expression for selecting only normal tweets is /rss/channel/item[not(starts-with(substring(substring-after(title,':'),2),'@')). To select only the first item, append [1] (making it /rss/channel/item[not(starts-with(substring(substring-after(title,':'),2),'@'))][1]). To select the last number of items, instead append [position()<=#] where # is the number if items you want.
For those interested in what the XPath does: first, the /rss/channel/item is analogous to a file path, where folders are equivalent to XML nodes. The difference here is that there can be more than one node with each name, and the expression matches them all. The part inside the brackets is evaluated from the inside out. substring-after gets the value of the part of the title attribute after the colon (removing your username and the colon). substring gets rid of the remaining space. starts-with tells the expression to only match those nodes for which the first character in our trimmed string is an @, and then not inverts it to select only those for which the first character is not @. Finally, the portion in the second set of brackets tells the expression to return either only the first item or the first x items that the rest of the expression matches.
This still isn’t the perfect solution, since it doesn’t filter retweets, which is especially undesirable if Twitter’s official retweets give you credit for others’ tweets. I don’t know, and can’t be bothered to check.