forked from venthur/gscholar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved CLI part into seperate script. Updated setup.py accordingly
- Loading branch information
Showing
4 changed files
with
83 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
|
||
import optparse | ||
import logging | ||
import sys | ||
import os | ||
|
||
import gscholar as gs | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
if __name__ == "__main__": | ||
usage = 'Usage: %prog [options] {pdf | "search terms"}' | ||
parser = optparse.OptionParser(usage) | ||
parser.add_option("-a", "--all", action="store_true", dest="all", | ||
default=False, help="show all bibtex results") | ||
parser.add_option("-d", "--debug", action="store_true", dest="debug", | ||
default=False, help="show debugging output") | ||
parser.add_option("-r", "--rename", action="store_true", dest="rename", | ||
default=False, help="rename file (asks before doing it)") | ||
parser.add_option("-f", "--outputformat", dest='output', | ||
default="bibtex", | ||
help="Output format. Available formats are: bibtex, endnote, refman, wenxianwang [default: %default]") | ||
parser.add_option("-s", "--startpage", dest='startpage', | ||
help="Page number to start parsing PDF file at.") | ||
(options, args) = parser.parse_args() | ||
if options.debug is True: | ||
logging.basicConfig(level=logging.DEBUG) | ||
if options.output == 'bibtex': | ||
outformat = gs.FORMAT_BIBTEX | ||
elif options.output == 'endnote': | ||
outformat = gs.FORMAT_ENDNOTE | ||
elif options.output == 'refman': | ||
outformat = gs.FORMAT_REFMAN | ||
elif options.output == 'wenxianwang': | ||
outformat = gs.FORMAT_WENXIANWANG | ||
if len(args) != 1: | ||
parser.error("No argument given, nothing to do.") | ||
sys.exit(1) | ||
args = args[0] | ||
pdfmode = False | ||
if os.path.exists(args): | ||
logger.debug("File exist, assuming you want me to lookup the pdf: {filename}.".format(filename=args)) | ||
pdfmode = True | ||
biblist = gs.pdflookup(args, all, outformat, options.startpage) | ||
else: | ||
logger.debug("Assuming you want me to lookup the query: {query}".format(query=args)) | ||
biblist = gs.query(args, outformat, options.all) | ||
if len(biblist) < 1: | ||
print("No results found, try again with a different query!") | ||
sys.exit(1) | ||
if options.all is True: | ||
logger.debug("All results:") | ||
for i in biblist: | ||
print(i) | ||
else: | ||
logger.debug("First result:") | ||
print(biblist[0]) | ||
if options.rename is True: | ||
if not pdfmode: | ||
print("You asked me to rename the pdf but didn't tell me which file to rename, aborting.") | ||
sys.exit(1) | ||
else: | ||
gs.rename_file(args, biblist[0]) | ||
|
||
# vim: set filetype=python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from gscholar.gscholar import * | ||
|
||
__VERSION__ = '1.3.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
#!/usr/bin/env python | ||
|
||
|
||
from distutils.core import setup | ||
from setuptools import setup | ||
|
||
import gscholar | ||
|
||
setup(name='gscholar', | ||
version=gscholar.__VERSION__, | ||
description='Python library to query Google Scholar.', | ||
long_description='This package provides a python package and CLI to query google scholar and get references in various formats (e.g. bibtex, endnote, etc.)', | ||
classifiers=[ | ||
'Development Status :: 5 :: Production/Stable', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3.6', | ||
], | ||
keywords='google scholar cli', | ||
author='Bastian Venthur', | ||
author_email='[email protected]', | ||
url='http://github.com/venthur/gscholar', | ||
packages=['gscholar'], | ||
scripts=['bin/gscholar'], | ||
license='MIT', | ||
) |