-
Notifications
You must be signed in to change notification settings - Fork 6
/
article-epub.py
executable file
·45 lines (40 loc) · 1.28 KB
/
article-epub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import article_epub
import sys
import requests
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-u",type=str,help='URL of article',
default=None,metavar='URL')
parser.add_argument("-d",type=str,help='DOI of article'
,default=None,metavar='DOI')
parser.add_argument("-t",type=str,help='Title of article',
default=None,metavar='TITLE')
parser.add_argument("-o",type=str,help='Name of output file',
default=None,metavar='FILE')
parser.add_argument("-p",help='List supported publishers',
action="store_true")
args = parser.parse_args()
def main():
if args.p:
pubs = article_epub.list_publishers()
print('Available publishers:')
for i in pubs:
print('• '+i)
sys.exit()
if args.u != None:
url = args.u
elif args.d != None:
url = article_epub.url_from_doi(args.d)
elif args.t != None:
url = article_epub.url_from_title(args.t)
else:
sys.exit('Must provide URL, DOI or title')
art = article_epub.match_publisher(url=url,doi=args.d)
art.soupify()
art.extract_data()
art.epubify(args.o)
print('\nCitation: '+art.get_citation())
print('Filename: '+art.output)
if __name__ == "__main__":
main()