Repository navigation
Expand file tree
/
Copy pathtemplate.py
More file actions
81 lines (63 loc) · 2.45 KB
/
Copy pathtemplate.py
File metadata and controls
81 lines (63 loc) · 2.45 KB
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
"""Database configuration template
====================================
This script provides you a example of self-defined dataloader
to construct your own local database. You need to know the
common phases in constructing local database.
1. Extracting data from datasource
2. Preprocessing data before pouring them into database
3. Import data into database
4. Postpross after import
The four steps in correlated with four functions: read,
preprocess, write, postprocess.
There are two things you need to do: 1. Define a Loader class
based on ba.Loader; 2. Set a config in a dict.
There are several loaders predefine in the bearalpha, however,
things may never be enough. We provided the examples of self-
defined loader.
And you can store the loader and the config into bearalpha's
cache, just make sure that you name the loader with 'Loader'
in it and name the config with 'baconfig' in it. Then run the
shell command `ba store <your file path in module fromat>`, like
`ba store database.dataloader`.
"""
import bearalpha as ba
# self defined data loader
class MyLoader(ba.Loader):
# functions you must accomplish
# 1. self.read; 2. self.write
# functions you may want to accomplish
# 1. self.preprocess; 2. self.postprocess
# all of them takes no argument, to get
# the input argument, use self.<fucntion name>args instead
def read(self):
# get argument by self.readargs
pass
def write(self):
# get argument by self.writeargs
pass
def preprocess(self):
# get argument by self.preprocessargs
pass
def postprocess(self):
# get argument by self.postprocessargs
pass
# config name must contains `baconfig` or it will not be recognized
baconfig_name = dict(
# any loader you use, current support for ba.Local
loader = ba.Local,
# RECOMMEND: your database path stored in ba.Cache(),
# or any string type path to your database file / service
database = "path or connect string to your database",
# table you want to store data in
table = "table_name",
# OPTIONAL: keyword arguments for preprocess function
preprocessargs = dict(),
# OPTIONAL: keyword arguments for read function
readargs = dict(),
# OPTIONAL: keyward arguments for write function
writeargs = dict(),
# OPTIONAL: keyword arguments for postprocess function
posprocessargs = dict(),
)
if __name__ == "__main__":
baconfig_name['loader'](baconfig_name)()