summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Gallo <aamsgallo@gmail.com>2018-10-09 02:18:18 +0200
committerAlejandro Gallo <aamsgallo@gmail.com>2018-10-09 02:18:18 +0200
commit6fbb00cc8a3fda4dc13ae3d21a882d7b5c6bbf69 (patch)
tree660547e744957a3f06b65a998f2cf955ce604b0e
parent50188525b329d3e0503284101e78114beb07ddb1 (diff)
Add experimental addsads
-rw-r--r--papis/ads.py93
-rw-r--r--papis/commands/explore.py78
2 files changed, 171 insertions, 0 deletions
diff --git a/papis/ads.py b/papis/ads.py
new file mode 100644
index 00000000..ebd73aaa
--- /dev/null
+++ b/papis/ads.py
@@ -0,0 +1,93 @@
+try:
+ import logging
+ logger = logging.getLogger('papis:ads')
+ import ads
+except ImportError:
+ logger.warning(
+ 'You need the package ads, try "pip3 install ads"'
+ )
+
+fields = [
+ "abstract",
+ "ack",
+ "aff",
+ "arxiv_class",
+ "author",
+ "bibgroup",
+ "bibstem",
+ "body",
+ "citation_count",
+ "database",
+ "doi",
+ "first_author",
+ "identifier",
+ "issue",
+ "keyword",
+ "lang",
+ "page",
+ "read_count",
+ "title",
+ "volume",
+ "year",
+ "sort",
+]
+
+ads.config.token = 'pBZxhQUlTV8NDX2kbfqCFOb8pZpjx3DHwhhjTyR0'
+
+def paper_to_dict(paper):
+ #keys = paper.keys()
+ data = paper._raw
+ if isinstance(paper.author, list):
+ data['author'] = ' and '.join(paper.author)
+ if isinstance(paper.title, list):
+ data['title'] = paper.title[0]
+ # if isinstance(paper.doi, list):
+ # data['doi'] = paper.doi
+ # else:
+ # del data['doi']
+ return data
+
+
+def get_data(
+ query=None,
+ max_results=30,
+ **kwargs
+ ):
+ """
+ :param abstract: The abstract of the record
+ :param ack: The acknowledgements section of an article
+ :param aff: An array of the authors' affiliations
+ :param arxiv_class: The arXiv class the pre-print was submitted to
+ :param author: An array of the author names associated with the record
+ :param bibgroup: The bibliographic groups that the bibcode has been
+ associated with
+ :param bibstem: The abbreviated name of the journal or publication, e.g.,
+ ApJ.
+ :param body: The full text content of the article
+ :param citation_count: Number of citations the item has received
+ :param database: Database the record is associated with (astronomy,
+ physics, or general). By default, all three databases are searched; to
+ limit to astronomy articles, add fq=database:astronomy to the URL
+ :param doi: Digital object identifier of the article
+ :param first_author: The first author of the article
+ :param identifier: An array of alternative identifiers for the record. May
+ contain alternate bibcodes, DOIs and/or arxiv ids.
+ :param issue: Issue the record appeared in
+ :param keyword: An array of normalized and un-normalized keyword values
+ associated with the record
+ :param lang: The language of the article's title
+ :param page: Starting page
+ :param read_count: Number of times the record has been viewed within in a
+ 90-day windows (ads and arxiv)
+ :param title: The title of the record
+ :param volume: Volume the record appeared in
+ :param year: The year the article was published
+ :param sort: Any of the fields
+ """
+ query_dict = {k: kwargs[k] for k in kwargs if kwargs[k]}
+ query_dict['q'] = 'ein'
+ papers = ads.SearchQuery(
+ rows=max_results,
+ query_dict=query_dict
+ )
+ return [paper_to_dict(p) for p in papers]
diff --git a/papis/commands/explore.py b/papis/commands/explore.py
index 15bbb615..46e5bd43 100644
--- a/papis/commands/explore.py
+++ b/papis/commands/explore.py
@@ -97,6 +97,7 @@ import logging
import papis.commands.add
import papis.commands.export
import papis.api
+import papis.ads
logger = logging.getLogger('explore')
@@ -314,6 +315,83 @@ def dissemin(ctx, query):
logger.info('{} documents found'.format(len(docs)))
+@cli.command('ads')
+@click.pass_context
+@click.help_option('--help', '-h')
+@click.option('-q', '--query', default=None)
+@click.option("--abstract",
+ help="The abstract of the record")
+@click.option("--ack",
+ help="The acknowledgements section of an article")
+@click.option("--aff",
+ help="An array of the authors' affiliations")
+@click.option("--arxiv_class",
+ help="The arXiv class the pre-print was submitted to")
+@click.option("--author",
+ help="An array of the author names associated with the record")
+@click.option("--bibgroup",
+ help="The bibliographic groups that the bibcode has been associated with")
+@click.option("--bibstem",
+ help="The abbreviated name of the journal or publication, e.g., ApJ.")
+@click.option("--body",
+ help="The full text content of the article")
+@click.option("--citation_count",
+ help="Number of citations the item has received")
+@click.option("--database",
+ help="Database the record is associated with (astronomy, physics, or general). By default, all three databases are searched")
+@click.option("--doi",
+ help="Digital object identifier of the article")
+@click.option("--first_author",
+ help="The first author of the article")
+@click.option("--identifier",
+ help="An array of alternative identifiers for the record. May contain alternate bibcodes, DOIs and/or arxiv ids.")
+@click.option("--issue",
+ help="Issue the record appeared in")
+@click.option("--keyword",
+ help="An array of normalized and un-normalized keyword values associated with the record")
+@click.option("--lang",
+ help="The language of the article's title")
+@click.option("--page",
+ help="Starting page")
+@click.option("--read_count",
+ help="Number of times the record has been viewed within in a 90-day windows (ads and arxiv)")
+@click.option("--title",
+ help="The title of the record")
+@click.option("--volume",
+ help="Volume the record appeared in")
+@click.option("--year",
+ help="The year the article was published")
+@click.option(
+ '-s', '--sort', default=None,
+ type=click.Choice(papis.ads.fields)
+)
+@click.option(
+ "--max-citations", "-m", default=-1,
+ help='Number of citations to be retrieved'
+)
+def adds(ctx, query, sort, max_citations, **kwargs):
+ """
+ Look for documents on dissem.in
+
+ Examples of its usage are
+
+ papis explore ads -q 'Albert einstein' pick cmd 'firefox {doc[url]}'
+
+ """
+ logger = logging.getLogger('explore:ads')
+ logger.info('Looking up...')
+ data = papis.ads.get_data(
+ query=query,
+ sort=sort,
+ max_results=max_citations,
+ **kwargs
+ )
+ docs = [papis.document.from_data(data=d) for d in data]
+ ctx.obj['documents'] += docs
+ logger.info('{} documents found'.format(len(docs)))
+
+
+
@cli.command('lib')
@click.pass_context
@click.help_option('--help', '-h')