Skip to content

Instantly share code, notes, and snippets.

@kkirsanov
Created November 28, 2011 12:26
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 kkirsanov/1400214 to your computer and use it in GitHub Desktop.
Save kkirsanov/1400214 to your computer and use it in GitHub Desktop.
import System.IO
import System.IO.Error
import Control.Monad
import Network.HTTP
import qualified Data.Map as Map
type FreqDB = Map.Map String Integer
updateFreq freq word = Map.insertWith' (+) word 1 freq
showFreq :: (String, Integer) -> String
showFreq tupl = show (fst tupl) ++ ":" ++ show ( snd tupl) where
f = filter (`notElem` "\n")
main = do
inh <- readFile "nums.csv"
let l = lines inh
userNames <- mapM getUser l
let nullfreq = Map.empty :: FreqDB
let freq = Map.toList $ foldl updateFreq nullfreq userNames
mapM_ (putStrLn . showFreq) freq
getUser :: String -> IO String
getUser phone =
simpleHTTP (getRequest $ "http://smsbilling.lalala.com/getpartnerbynum/?phone="++phone) >>= fmap (take 200) . getResponseBody
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment