Created
November 28, 2011 12:26
-
-
Save kkirsanov/1400214 to your computer and use it in GitHub Desktop.
This file contains 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
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