Skip to content

Instantly share code, notes, and snippets.

@dvdsgl
Created May 14, 2010 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdsgl/401265 to your computer and use it in GitHub Desktop.
Save dvdsgl/401265 to your computer and use it in GitHub Desktop.
#!/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