script to extract tweets about…

This was the Powershell code I used to create the all the podcasts I’ve ever tweeted about post.

I downloaded the tweets from Twitter itself – I think there was a link somwhere within ‘Settings’

The .csv file looks like this:


So the code is:

$PodTweets = Import-Csv c:temptweets.csv | ? text -like "*podcast*" $TweetsAsHtml = foreach ($P in $PodTweets) { # write-output $P.timestamp.Substring(0,10) # Splitting the tweet text into words to allow for the processing of urls $TweetTextAsArray = $P.text.split(" ") $TextWithLink="" foreach ($Word in $TweetTextAsArray) { if ($Word -like "http:*") { # if there is an expanded_url, then use that instead if ($P.expanded_urls -ne "") { $Word = $P.expanded_urls # for some reason the expanded url is sometimes repeated in the download if ($Word -like "*,*") { $Word = $Word.split(",")[0] } } # re-format the URL as a link $Word = "`<a href=`"$Word`"`>$Word`<`/a`>" } $TextWithLink = "$TextWithLink$Word " } # create an object and output that $properties = @{'TweetDate'=$P.timestamp.Substring(0,10); 'TweetText'=$TextWithLink} $ReformattedTweets = New-Object –Type PSObject –Prop $properties write-output $ReformattedTweets } $TweetsAsHtml | fl | out-file -encoding ascii -FilePath x.txt -width 1000