packages feed

haskell-fake-user-agent (empty) → 0.0.1

raw patch · 5 files changed

+59/−0 lines, 5 filesdep +basedep +bytestringdep +lenssetup-changed

Dependencies added: base, bytestring, lens, tagsoup, wreq

Files

+ HTTP/FakeUserAgent.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE OverloadedStrings #-}+module HTTP.FakeUserAgent (getBrowserString) where++import Control.Lens ((^?))+import Data.ByteString.Lazy (ByteString, unpack)+import Data.Char (chr)+import Network.Wreq (get, responseBody)+import Text.HTML.TagSoup (parseTags, innerText, Tag(TagOpen, TagClose), (~/=))++getVersionsList :: [Tag ByteString] -> [Tag ByteString]+getVersionsList tags =+    let tags1 = (drop 1 . dropWhile (~/= TagOpen ("div" :: String) [("id", "liste")])) tags in+        takeWhile (~/= TagClose ("div" :: String)) tags1++getVersions :: [Tag ByteString] -> [ByteString] -> [ByteString]+getVersions [] accum = reverse accum+getVersions tags accum = +    let tags1 = (drop 1 . dropWhile (~/= TagOpen ("li" :: String) [])) tags+        match = takeWhile (~/= TagClose ("li" :: String)) tags1+        tags2 = (drop 1 . dropWhile (~/= TagClose ("li" :: String))) tags1 in+        case match of+            [] -> getVersions tags2 accum+            _  -> getVersions tags2 ((innerText match):accum)++getBrowserString :: String -> IO String+getBrowserString name = do+    resp <- get ("http://useragentstring.com/pages/" ++ name ++ "/")+    let Just body = resp ^? responseBody+    let tags = parseTags body+    let versions = getVersions (getVersionsList tags) []+    let v:_ = versions+    return $ (map (chr . fromEnum) . unpack) v
+ LICENSE view
@@ -0,0 +1,1 @@+This code is public domain. You can do whatever you want with it.
+ README.md view
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ haskell-fake-user-agent.cabal view
@@ -0,0 +1,24 @@+-- Initial haskell-fake-user-agent.cabal generated by cabal init.  For +-- further documentation, see http://haskell.org/cabal/users-guide/++name:                haskell-fake-user-agent+version:             0.0.1+synopsis:            Simple library for retrieving current user agent strings+-- description:         +license:             PublicDomain+license-file:        LICENSE+author:              grzegorzgoldapl+maintainer:          contact@grzegorzgolda.com+-- copyright:           +category:            Web+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++library+  exposed-modules:     HTTP.FakeUserAgent+  -- other-modules:       +  other-extensions:    OverloadedStrings+  build-depends:       base >=4.8 && <4.9, lens >=4.14 && <4.15, bytestring >=0.10 && <0.11, wreq >=0.4 && <0.5, tagsoup >=0.13 && <0.14+  -- hs-source-dirs:      +  default-language:    Haskell2010