aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2018-04-10 10:44:44 -0400
committerKen Kellner <ken@kenkellner.com>2018-04-10 10:44:44 -0400
commite7494fe7d2647ef61f1136606f4f3fa890625ded (patch)
tree3c5137e13ff0e776b830a4b3c28a3ac09c03822b
parent11a05918ab7d37b2939523af5c1865c32ee63c79 (diff)
Add better argument setup and option to customize output file name
-rwxr-xr-xarticle-epub.py32
-rw-r--r--article_epub/publisher.py10
2 files changed, 31 insertions, 11 deletions
diff --git a/article-epub.py b/article-epub.py
index 9689abb..9ccab6d 100755
--- a/article-epub.py
+++ b/article-epub.py
@@ -2,21 +2,37 @@
import article_epub
import sys
import requests
+import argparse
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument("-u","--url",type=str,help='URL of article',default=None)
+parser.add_argument("-d","--doi",type=str,help='DOI of article',default=None)
+parser.add_argument("-o","--out",type=str,help='Name of output file',
+ default=None,metavar='FILE')
+parser.add_argument("-p","--publishers",help='List supported publishers',
+ action="store_true")
+args = parser.parse_args()
def main():
- if sys.argv[1] == '-d':
- print("Getting URL from DOI........",end='',flush=True)
- url = requests.get('https://doi.org/'+sys.argv[2]).url
- doi = sys.argv[2]
- print('done')
- elif sys.argv[1] == '--list-publishers':
+
+ if args.publishers:
pubs = article_epub.publisher.list_publishers()
print('Available publishers:')
for i in pubs:
print('• '+i.__name__)
sys.exit()
+
+ if args.doi == None and args.url == None:
+ sys.exit('Must provide either URL or DOI')
+
+ if args.doi != None:
+ print("Getting URL from DOI........",end='',flush=True)
+ url = requests.get('https://doi.org/'+args.doi).url
+ doi = args.doi
+ print('done')
else:
- url = sys.argv[1]
+ url = args.url
doi = None
domain = ".".join(url.split("//")[-1].split("/")[0] \
@@ -30,7 +46,7 @@ def main():
art.soupify()
art.extract_data()
- art.epubify()
+ art.epubify(args.out)
print('\nCitation: '+art.citation)
print('Filename: '+art.output)
diff --git a/article_epub/publisher.py b/article_epub/publisher.py
index 7216d7d..4f728f5 100644
--- a/article_epub/publisher.py
+++ b/article_epub/publisher.py
@@ -120,7 +120,7 @@ class Publisher(object):
self.get_references()
print('done')
- def epubify(self):
+ def epubify(self,output=None):
"""Convert data into epub format"""
all_authors = ''
@@ -138,8 +138,12 @@ class Publisher(object):
args.append('-M')
args.append('author="'+all_authors+'"')
args.append('--parse-raw')
-
- self.output = self.author_surnames[0]+'_'+self.year+'.epub'
+
+ if output == None:
+ self.output = self.author_surnames[0]+'_'+self.year+'.epub'
+ else:
+ self.output = output
+
output_raw = '/tmp/raw.epub'
combined = ''