hs-nombre-generator 0.2.0.0 → 0.2.1.0
raw patch · 3 files changed
+49/−2 lines, 3 files
Files
- Web/NombreGenerator/RandomUtil.hs +16/−0
- Web/NombreGenerator/Scrapper/BsAs.hs +30/−0
- hs-nombre-generator.cabal +3/−2
+ Web/NombreGenerator/RandomUtil.hs view
@@ -0,0 +1,16 @@+module Web.NombreGenerator.RandomUtil (randTriples) where++import System.Random+import Control.Monad++pick :: [a] -> IO a+pick list = randomRIO (0, length list - 1) >>= return . (list !!)++takeRandom :: Int -> [a] -> IO [a]+takeRandom n list = replicateM n $ pick list++format :: [String] -> String+format [a,b,c] = a ++ ", " ++ b ++ " " ++ c++randTriples :: Int -> [String] -> IO [String]+randTriples n list = replicateM n (fmap format $ takeRandom 3 list)
+ Web/NombreGenerator/Scrapper/BsAs.hs view
@@ -0,0 +1,30 @@+module Web.NombreGenerator.Scrapper.BsAs (scrap) where++import Text.XML.HXT.Core+import Text.HandsomeSoup++fromWeb = fromUrl "http://www.buenosaires.gob.ar/areas/registrocivil/nombres/busqueda/imprimir.php?sexo=ambos"++fromFile = readDocument [withParseHTML yes,+ withInputEncoding isoLatin1,+ withCheckNamespaces no,+ withParseByMimeType no,+ withWarnings no] "Nombres.html"++getDoc = traceMsg 0 "Downloading..." >>>+ --fromWeb >>>+ fromFile >>>+ traceMsg 0 "Parsing..."++scrap :: IO [String]+scrap = runX findNames++findNames :: IOSLA (XIOState ()) XmlTree String+findNames = getDoc >>>+ css ".contenido tbody tr" >>>+ listA (+ getChildren >>>+ hasName "td"+ /> getText+ )+ >>. map head
hs-nombre-generator.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: hs-nombre-generator-version: 0.2.0.0+version: 0.2.1.0 synopsis: Name generator. description: Random name generator with web scrapping. license: MIT@@ -17,7 +17,8 @@ executable hs-nombre-generator main-is: Web/NombreGenerator.hs ghc-options: -O2- -- other-modules: + other-modules: Web.NombreGenerator.RandomUtil+ , Web.NombreGenerator.Scrapper.BsAs build-depends: base >=4.0 && <4.8 , hxt , HandsomeSoup