document parsing works now

parent 72a4c71e
# Open Alex Database API Crawler for GarganText
## Compilation
For non-GHC stuff, use Nix.
For GHC, use ghcup and use GHC 8.10.7.
## Running
``` shell
......
......@@ -16,6 +16,10 @@ main = do
"Fetch OpenAlex concepts (https://docs.openalex.org/api-entities/concepts/concept-object)"
(const fetchConcepts)
(pure ())
addCommand "works"
"Fetch OpenAlex works (https://docs.openalex.org/api-entities/works/work-object)"
(const fetchWorks)
(pure ())
runCmd ()
......@@ -27,5 +31,13 @@ fetchConcepts _ = do
case ec of
Left err -> putText $ "error: " <> show err
Right c -> do
putText "c"
putText $ show c
fetchWorks :: () -> IO ()
fetchWorks _ = do
-- ec <- OA.fetchConcepts (Just 1) (Just 1) Nothing
ew <- OA.fetchWorks (Just 1) (Just 1) (Just "*")
case ew of
Left err -> putText $ "error: " <> show err
Right w -> do
putText $ show w
......@@ -14,6 +14,7 @@ rec {
ps.tqdm
]);
nonhsBuildInputs = with pkgs; [
gmp
jupyter
pythonEnv
zlib
......@@ -21,6 +22,6 @@ rec {
#libPaths = pkgs.lib.makeLibraryPath nonhsBuildInputs;
shell = pkgs.mkShell {
name = "openalex";
buildInputs = hsBuildInputs ++ nonhsBuildInputs;
buildInputs = nonhsBuildInputs;
};
}
......@@ -14,7 +14,9 @@ module OpenAlex
( module OpenAlex.Client
, module OpenAlex.Types
-- , fetchConcepts'
, fetchConcepts )
, fetchConcepts
, fetchWorks
)
where
-- import Data.Aeson
......@@ -27,7 +29,7 @@ import Network.HTTP.Client.TLS (tlsManagerSettings)
import Protolude
import OpenAlex.Client
import OpenAlex.ServantClientLogging
import OpenAlex.Types
import OpenAlex.Types (ListOf(..), Page, PerPage, Cursor, Concept, Work)
import Servant.Client (BaseUrl(..), ClientEnv(..), ClientError, Scheme(Https), defaultMakeClientRequest, mkClientEnv, runClientM)
defaultClientEnv :: IO ClientEnv
......@@ -46,6 +48,11 @@ fetchConcepts mPage mPerPage mCursor = do
env <- defaultClientEnv
runClientM (concepts mPage mPerPage mCursor) env
fetchWorks :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> IO (Either ClientError (ListOf Work))
fetchWorks mPage mPerPage mCursor = do
env <- defaultClientEnv
runClientM (works mPage mPerPage mCursor) env
-- fetchConcepts' :: IO (Either Text (ListOf Concept))
-- fetchConcepts' = do
-- manager <- newManager tlsManagerSettings
......
......@@ -16,7 +16,7 @@ import Protolude
import Servant.API
import Servant.Client
import OpenAlex.Types
import OpenAlex.Types (Page, PerPage, Cursor, ListOf(..), Concept, Work)
type API_URL = Text
apiUrl :: API_URL
......@@ -37,9 +37,19 @@ type OpenAlexAPI =
-- TODO: filter, search, sort
:> Get '[JSON] (ListOf Concept)
-- https://docs.openalex.org/api-entities/works
:<|> "works"
:> QueryParam "page" Page
:> QueryParam "per-page" PerPage
:> QueryParam "cursor" Cursor
-- TODO: filter, search, sort
:> Get '[JSON] (ListOf Work)
openAlexApi :: Proxy OpenAlexAPI
openAlexApi = Proxy
concepts :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> ClientM (ListOf Concept)
concepts {- :<|> fetch -} = client openAlexApi
works :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> ClientM (ListOf Work)
concepts :<|> works = client openAlexApi
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment