Created
May 14, 2010 15:08
-
-
Save dvdsgl/401265 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/runhaskell | |
import Data.List (isInfixOf) | |
import Web.Twitter (getUserTimeline) | |
import Web.Twitter.Monad (runTM) | |
import Web.Twitter.Fetch (nullAuthUser) | |
import Web.Twitter.Types (Status (..)) | |
username = "jonobacon" | |
patterns = ["rock", "awesome", "jam"] | |
-- A simple accumulator that counts matches of a pattern | |
type Counter = (Pattern, Int) | |
type Pattern = String | |
-- The Pattern matching predicate is simply: | |
match pattern = isInfixOf pattern | |
-- Create a Counter for a pattern in a list of Strings | |
newCounter pattern strings = (pattern, length matches) | |
where matches = filter (match pattern) strings | |
getTweets username = runTM nullAuthUser $ do | |
getUserTimeline (Just username) Nothing Nothing | |
main = do | |
tweets <- getTweets username | |
let statuses = map statusText tweets | |
counters = map (flip newCounter statuses) patterns | |
print counters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment