Reading Twitter (And Detecting Speed Traps)

by Aug 8, 2012

With just a couple lines of code, PowerShell can search for Twitter news. If you happen to live in Germany, then this would tell you the latest speed traps in Lower Saxony:

$cutoff = (Get-Date).AddDays(-1).ToString('yyyy-MM-dd')

$url = "http://search.twitter.com/search.atom?q=blitzer_de
&rpp=400&result_type=recent&since_id=$cutoff" $xml = New-Object xml $xml.load($url) $xml.feed.entry | Where-Object { $_.Title -like '*DE-NI*' } | Select-Object -ExpandProperty Title

Basically, the code gets an XML object and submits the search query to Twitter. If you'd like to search for different information, take a look at the search syntax: http://dev.twitter.com/doc/get/search.

Basically, the code gets an XML object and submits the search query to Twitter. If you'd like to search for different information, take a look at the search syntax: http://dev.twitter.com/doc/get/search.

Note that the XML object can download the information only if you have a direct Internet connection. If your connection goes through a proxy, you are out of luck and would have to use a proxy-friendly way of downloading the URL data.

Twitter This Tip! ReTweet this Tip!