-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (34 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
46 lines (34 loc) · 1.42 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
import argparse
import os
from dotenv import load_dotenv
from datalibrary.extract import DataLibrary, get_data
from datalibrary.load import load_to_db, save_to_excel
from datalibrary.transform import transform
load_dotenv() # take environment variables from .env.
def main():
"""
Executes the ETL (Extract, Transform, Load) process to fetch data from VAM Data Library, process the data, and load it into a database and/or save it to an Excel file.
There are three data points being loaded:
- Survey Information
- User Information
- Survey Resources
"""
dl_api_data = get_data(DataLibrary(os.getenv("DATALIB_API_KEY")))
processed_data = transform(dl_api_data)
# Parse command-line arguments
parser = argparse.ArgumentParser(
description="Export Data Library data to CSV or database."
)
parser.add_argument("--csv", action="store_true", help="Export data to CSV files")
parser.add_argument("--db", action="store_true", help="Upload data to a database")
args = parser.parse_args()
if args.csv:
save_to_excel(processed_data)
print("Data exported to CSV files.")
if args.db:
load_to_db(processed_data)
print("Data uploaded to the database.")
if not args.csv and not args.db:
print("No action specified. Use --csv or --db to export data.")
if __name__ == "__main__":
main()