-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.py
executable file
·110 lines (99 loc) · 3.44 KB
/
loader.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
"""Metadata loader
Call custom, business specific, workflows to ingest metadata into Thoth.
"""
import argparse
import logging
from obploader import OBPBookLoader
from obpchapterloader import ObpChapterLoader
from obpchapterabstractloader import ObpChapterAbstractLoader
from punctumloader import PunctumBookLoader
from punctumchapterloader import PunctumChapterLoader
from africanmindsloader import AfricanMindsBookLoader
from whploader import WHPLoader
from whpchapterloader import WHPChapterLoader
from uwploader import UWPLoader
from lseloader import LSELoader
from editusloader import EDITUSLoader
from eduepbloader import EDUEPBLoader
from eduepbchapterloader import EDUEPBChapterLoader
from edituschapterloader import EDITUSChapterLoader
from ubiquityloader import UbiquityPressesLoader
from uolloader import UOLLoader
from leuvenloader import LeuvenLoader
from lharmattanloader import LHarmattanLoader
LOADERS = {
"OBP": OBPBookLoader,
"OBP-chapters": ObpChapterLoader,
"OBP-chapter-abstracts": ObpChapterAbstractLoader,
"punctum": PunctumBookLoader,
"punctum-chapters": PunctumChapterLoader,
"AM": AfricanMindsBookLoader,
"WHP": WHPLoader,
"WHP-chapters": WHPChapterLoader,
"UWP": UWPLoader,
"LSE": LSELoader,
"EDITUS": EDITUSLoader,
"EDITUS-chapters": EDITUSChapterLoader,
"EDUEPB": EDUEPBLoader,
"EDUEPB-chapters": EDUEPBChapterLoader,
"Ubiquity-presses": UbiquityPressesLoader,
"UOL": UOLLoader,
"Leuven": LeuvenLoader,
"LHarmattan": LHarmattanLoader,
}
ARGS = [
{
"val": "--file",
"dest": "file",
"action": "store",
"default": "./data/all-book-metadata.csv",
"help": "Path to metadata CSV file"
}, {
"val": "--client-url",
"dest": "client_url",
"action": "store",
"default": "https://api.thoth.pub",
"help": "Thoth's GraphQL endpoint URL, excluding '/graphql'"
}, {
"val": "--email",
"dest": "email",
"action": "store",
"help": "Authentication email address"
}, {
"val": "--password",
"dest": "password",
"action": "store",
"help": "Authentication password"
}, {
"val": "--mode",
"dest": "mode",
"action": "store",
"default": "OBP",
"help": "Publisher key, one of: {}".format(
', '.join("%s" % (key) for (key, val) in LOADERS.items()))
}
]
def run(mode, metadata_file, client_url, email, password):
"""Execute a book loader based on input parameters"""
loader = LOADERS[mode](metadata_file, client_url, email, password)
loader.run()
def get_arguments():
"""Parse input arguments using ARGS"""
parser = argparse.ArgumentParser()
for arg in ARGS:
if 'default' in arg:
parser.add_argument(arg["val"], dest=arg["dest"],
default=arg["default"], action=arg["action"],
help=arg["help"])
else:
parser.add_argument(arg["val"], dest=arg["dest"], required=True,
action=arg["action"], help=arg["help"])
args = parser.parse_args()
return args
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO,
format='%(levelname)s:%(asctime)s: %(message)s')
ARGUMENTS = get_arguments()
run(ARGUMENTS.mode, ARGUMENTS.file, ARGUMENTS.client_url,
ARGUMENTS.email, ARGUMENTS.password)