以前書いたのを今みるとグダグダだ。やっぱコピペはダメだな。
今回feedを使ってみた。ファイルの読み込みだったらparseFeedFromFileを使う。
import Text.Feed.Import
import Text.Feed.Query
import Data.Maybe
main = do
rss <- parseFeedFromFile "test.rss"
mapM_ putStrLn $ map (fromJust . getItemTitle) (getFeedItems rss)
HTTPと組み合わせる場合は
import Text.Feed.Import
import Text.Feed.Query
import Data.Maybe
import Network.HTTP
eutils_url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/erss.cgi?rss_guid="
guid = "1ZQ4a7JQ6X8P3NJNZLWG_ML-XsrLQgH63A06CsXO-jG0m_iEe-"
getTitle = (take 60) . fromJust . getItemTitle
getItems = getFeedItems . fromJust . parseFeedString
main :: IO ()
main = do
res <- simpleHTTP $ getRequest $ eutils_url ++ guid
body <- getResponseBody res
mapM_ putStrLn $ map getTitle $ getItems body
実行すると
RMol: A Toolset for Transforming SD/Molfile structure inform
Adenosiland: Walking through adenosine receptors landscape.
Enzyme Informatics.
The Use of the R language for Medicinal Chemistry Applicatio
Similarity coefficients for binary chemoinformatics data: ov
Review on Chemogenomics approach: Interpreting antagonist ac
Immunotoxicity, Flow Cytometry and Chemoinformatics: A Revie
A Parallel Systematic-Monte Carlo Algorithm for exploring Co
Validation of drug-like inhibitors against Mycobacterium tub
Desirability-based Multi-criteria Virtual Screening of Selec
The use of glycoinformatics in glycochemistry.
Role of computational methods in pharmaceutical sciences.
High-throughput screening with a miniaturized radioligand co
Chemoinformatics: recent advances at the interfaces between
ReactionPredictor: Prediction of Complex Chemical Reactions
プロキシとかセッションなんかを使いたい場合にはNetwork.Browserを利用する。
Network.Browserは以下の機能が使えるハイレベルなモジュール。
- HTTP Authentication handling
- Transparent handling of redirects
- Cookie stores + transmission.
- Transaction logging
- Proxy-mediated connections.
browseのところに色々挟みこむとよろしくやってくれる(今回はなんもしてないけど)。職場で使う時にはプロキシを挟む必要があるためsimpleHTTPは使えない。
import Text.Feed.Import
import Text.Feed.Query
import Data.Maybe
import Network.HTTP
import Network.Browser (browse, request)
eutils_url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/erss.cgi?rss_guid="
guid = "1ZQ4a7JQ6X8P3NJNZLWG_ML-XsrLQgH63A06CsXO-jG0m_iEe-"
getTitle = (take 60) . fromJust . getItemTitle
getItems = getFeedItems . fromJust . parseFeedString . rspBody
main :: IO ()
main = do
(_, res) <- browse $ do
request $ getRequest $ eutils_url ++ guid
mapM_ putStrLn $ map getTitle $ getItems $ res
ちなみにRMolにはいまいち惹かれないなぁ。Rならではのメリットあるんだろうか?