Commit 260dc8be authored by Alexandre Delanoë's avatar Alexandre Delanoë

[INIT] init project + LGPL and GPLv3 compatibility

parents
.stack-work/
*~
\ No newline at end of file
# Changelog for arxiv
## Unreleased changes
Copyright Author name here (c) 2021
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import Distribution.Simple
main = defaultMain
module Main where
main :: IO ()
main = undefined
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.33.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 9b54afba258889accc35eff3ef449f2a043a780cfc51c974c3e2b0c7768d3bb8
name: arxiv-api
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/arxiv#readme>
homepage: https://github.com/githubuser/arxiv#readme
bug-reports: https://github.com/githubuser/arxiv/issues
author: Author name here
maintainer: example@example.com
copyright: 2021 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://github.com/githubuser/arxiv
library
exposed-modules:
Lib
other-modules:
Paths_arxiv_api
hs-source-dirs:
src
build-depends:
arxiv
, base >=4.7 && <5
, bytestring
, conduit
, http-conduit
, http-types
, mtl
, network
, resourcet
, tagsoup
default-language: Haskell2010
executable arxiv-exe
main-is: Main.hs
other-modules:
Paths_arxiv_api
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
arxiv
, base >=4.7 && <5
, bytestring
, conduit
, http-conduit
, http-types
, mtl
, network
, resourcet
, tagsoup
default-language: Haskell2010
test-suite arxiv-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_arxiv_api
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
arxiv
, base >=4.7 && <5
, bytestring
, conduit
, http-conduit
, http-types
, mtl
, network
, resourcet
, tagsoup
default-language: Haskell2010
name: arxiv-api
version: 0.1.0.0
github: ""
license: GPLv3
author: "Alexandre Delanoë"
maintainer: "alexandre+dev@delanoe.org"
copyright: "2021 CNRS/A. Delanoë"
# Upgrading LGPL arxiv source code to GPLv3
# https://opensource.stackexchange.com/questions/5637/use-lgpl-code-in-an-agpl-project
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/arxiv#readme>
dependencies:
- base >= 4.7 && < 5
- arxiv
- network
- http-conduit
- tagsoup
- conduit
- mtl
- resourcet
- http-types
- bytestring
library:
source-dirs: src
dependencies:
- arxiv
executables:
arxiv-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- arxiv
tests:
arxiv-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- arxiv
module Lib where
import qualified Network.Api.Arxiv as Ax
import Network.Api.Arxiv (Expression(..),
Field(..), (/*/), (/+/))
import Network.Socket (withSocketsDo)
import Network.HTTP.Simple as HT
import Network.HTTP.Conduit (parseRequest)
import Network.HTTP.Types.Status
import Data.List (intercalate)
import qualified Data.ByteString as B hiding (unpack)
import qualified Data.ByteString.Char8 as B (unpack)
import Data.Conduit ((.|))
import qualified Data.Conduit as C
import qualified Data.Conduit.List as CL
import Data.Function ((&))
import Text.HTML.TagSoup
import Control.Monad.Trans (liftIO)
import Control.Monad.Trans.Resource (MonadResource)
import Control.Applicative ((<$>))
search :: IO ()
search = withSocketsDo (execQuery makeQuery)
makeQuery :: Ax.Query
makeQuery =
let au = Exp $ Au ["Aaronson"]
t1 = Exp $ Ti ["quantum"]
t2 = Exp $ Ti ["complexity"]
x = au /*/ (t1 /+/ t2)
in Ax.Query {
Ax.qExp = Just x,
Ax.qIds = [],
Ax.qStart = 0,
Ax.qItems = 25}
type Soup = Tag String
execQuery :: Ax.Query -> IO ()
execQuery q = C.runConduitRes (searchAxv q .| outSnk)
----------------------------------------------------------------------
-- Execute query and start a source
----------------------------------------------------------------------
searchAxv :: MonadResource m => Ax.Query -> C.ConduitT () String m ()
searchAxv q =
let s = Ax.mkQuery q
in do rsp <- HT.httpBS =<< liftIO (parseRequest s)
case getResponseStatus rsp of
(Status 200 _) -> getSoup (getResponseBody rsp)
>>= results q
st -> error $ "Error:" ++ show st
----------------------------------------------------------------------
-- Consume page by page
----------------------------------------------------------------------
getSoup :: MonadResource m =>
B.ByteString -> C.ConduitT () String m [Soup]
getSoup b = concat <$> (C.yield b .| toSoup .| CL.consume)
----------------------------------------------------------------------
-- Receive a ByteString and yield Soup
----------------------------------------------------------------------
toSoup :: MonadResource m => C.ConduitT B.ByteString [Soup] m ()
toSoup = C.awaitForever (C.yield . parseTags . B.unpack)
----------------------------------------------------------------------
-- Yield all entries and fetch next page
----------------------------------------------------------------------
results :: MonadResource m =>
Ax.Query -> [Soup] -> C.ConduitT () String m ()
results q sp =
if Ax.exhausted sp
then C.yield ("EOT: " ++ show (Ax.totalResults sp) ++ " results")
else Ax.forEachEntryM_ sp (C.yield . mkResult)
>> searchAxv (Ax.nextPage q)
----------------------------------------------------------------------
-- Get data and format
----------------------------------------------------------------------
mkResult :: [Soup] -> String
mkResult sp = let aus = Ax.getAuthorNames sp
y = Ax.getYear sp
tmp = Ax.getTitle sp & clean ['\n', '\r', '\t']
ti = if null tmp then "No title" else tmp
in intercalate ", " aus ++ " (" ++ y ++ "): " ++ ti
where clean _ [] = []
clean d (c:cs) | c `elem` d = clean d cs
| otherwise = c:clean d cs
----------------------------------------------------------------------
-- Sink results
----------------------------------------------------------------------
outSnk :: MonadResource m => C.ConduitT String C.Void m ()
outSnk = C.awaitForever (liftIO . putStrLn)
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/2.yaml
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
extra-deps:
- arxiv-0.0.2@sha256:2e9299c132af5838a756c3e4eaf879e0a0cfa9a2c7e2925ad2936df7d37bc993,1587
# Override default flag values for local packages and extra-deps
# flags: {}
# Extra package databases containing global packages
# extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.5"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages:
- completed:
hackage: arxiv-0.0.2@sha256:2e9299c132af5838a756c3e4eaf879e0a0cfa9a2c7e2925ad2936df7d37bc993,1587
pantry-tree:
size: 280
sha256: 0a55ee0f4cb4337e0c8eea362b8895fe647493c53db76ed4d160589b79592fb4
original:
hackage: arxiv-0.0.2@sha256:2e9299c132af5838a756c3e4eaf879e0a0cfa9a2c7e2925ad2936df7d37bc993,1587
snapshots:
- completed:
size: 563099
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/2.yaml
sha256: 92b1a17e31d0a978fca4bf270305d4d1dd8092271bf60eafbc9349c890854026
original:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/2.yaml
main :: IO ()
main = putStrLn "Test suite not yet implemented"
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