New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bibtex-search

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bibtex-search - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

.cli.js.swp

117

index.js

@@ -1,2 +0,1 @@

#!/usr/bin/env node
'use strict';

@@ -7,16 +6,8 @@

const cheerio = require('cheerio');
const meow = require('meow');
const inquirer = require('inquirer');
const ora = require('ora');
const clipboardy = require('clipboardy');
const chalk = require('chalk');
const MAX_ARTICLES = 10;
const ACM_SEARCH_URL = 'https://dl.acm.org/results.cfm';
const ACM_REFERENCE_URL = 'https://dl.acm.org/exportformats.cfm';
const SCHOLAR_SEARCH_URL = 'https://scholar.google.com/scholar';
/**
* Searches ACM for the given query, returning an array of articles.
*/
async function search(query) {
async function searchAcm(query) {
const res = await got(ACM_SEARCH_URL, { query: { query } });

@@ -46,6 +37,22 @@ const selector = cheerio.load(res.body);

/**
* Retrieves the BibTeX reference for a given ACM ID.
*/
async function retrieveReference(id) {
async function searchScholar(query) {
const res = await got(SCHOLAR_SEARCH_URL, {
query: {
q: query,
hl: 'en'
}
});
const selector = cheerio.load(res.body);
const detailsSelector = selector('.gs_r.gs_or.gs_scl');
return detailsSelector.toArray().map(article => {
const articleSelector = selector(article);
const id = articleSelector.data('cid');
const title = articleSelector.find('.gs_rt > a').text();
const authors = articleSelector.find('.gs_a').text();
return { id, title, authors };
});
}
async function retrieveAcm(id) {
const query = {

@@ -61,63 +68,35 @@ id,

const cli = meow(`
Searches for BibTeX references.
async function retrieveScholar(id) {
const query = {
q: `info:${id}:scholar.google.com/`,
output: 'cite'
};
Usage:
$ bibtex-search <query>
`);
function buildQuestions(articles) {
const choices = articles.map(({ id, title, authors }, i) => ({
value: id,
name: `${title} ${chalk.dim(`(${authors})`)}`
}));
return [
{
choices,
pageSize: Infinity,
type: 'list',
name: 'article',
message: 'Which article are you looking for?'
}
];
const res = await got(SCHOLAR_SEARCH_URL, { query });
const selector = cheerio.load(res.body);
const url = selector(`a.gs_citi:contains(BibTeX)`).attr('href');
const refRes = await got(url);
return refRes.body;
}
async function main() {
const query = cli.input.join(' ');
if (!query) cli.showHelp();
const spinner = ora(`Searching for '${query}'`).start();
let articles;
try {
articles = await search(query);
articles = articles.slice(0, MAX_ARTICLES);
spinner.stop();
} catch (e) {
spinner.fail(`Something went wrong while searching: ${e}`);
process.exit(1);
/**
* Retrieves the BibTeX reference for a given source and id.
*/
exports.retrieve = async function retrieve(source, id) {
if (source === 'google') {
return retrieveScholar(id);
}
if (!articles.length) {
spinner.info(`No results found for query '${query}'.`);
process.exit(0);
}
return retrieveAcm(id);
};
const questions = buildQuestions(articles);
const { article } = await inquirer.prompt(questions);
spinner.start('Retrieving BibTeX reference');
let reference;
try {
reference = await retrieveReference(article);
} catch (e) {
spinner.fail(`Something went wrong while retrieving reference: ${e}`);
process.exit(1);
/**
* Searches the given source for a list of articles.
*/
exports.search = async function search(source, query) {
if (source === 'google') {
return searchScholar(query);
}
spinner.stop();
console.log(reference);
clipboardy.writeSync(reference);
spinner.succeed('Copied to clipboard!');
}
main();
return searchAcm(query);
};
{
"name": "bibtex-search",
"version": "0.1.3",
"version": "0.2.0",
"description": "Search for BibTeX references",
"main": "index.js",
"bin": "index.js",
"bin": "cli.js",
"repository": "https://github.com/ekmartin/bibtex-search",

@@ -11,3 +11,3 @@ "author": "Martin Ek <mail@ekmartin.com>",

"scripts": {
"start": "node index.js",
"start": "node cli.js",
"test": "yarn lint",

@@ -14,0 +14,0 @@ "lint": "yarn lint:prettier && yarn lint:eslint",

@@ -7,6 +7,7 @@ # bibtex-search [![Build Status](https://travis-ci.org/ekmartin/bibtex-search.svg?branch=master)](https://travis-ci.org/ekmartin/bibtex-search)

Currently uses [ACM's Digital Library](https://dl.acm.org/) to find papers, but
might support other sources in the future.
Currently uses [ACM's Digital Library](https://dl.acm.org/) and
[Google Scholar](https://scholar.google.com/) to find papers, but might support
other sources in the future.
## Installation and usage
## Installation

@@ -17,3 +18,15 @@ bibtex-search needs at least version 7.6 of Node.js installed.

$ npm install --global bibtex-search
```
## Usage
```bash
$ bibtex-search <query>
Options:
--source, -s Where to find papers from - valid options: [google, acm]
Examples:
$ bibtex-search bayou
$ bibtex-search --source google zaharia spark
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc