-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import argparse | ||
import logging | ||
|
||
from salamanca import data | ||
from salamanca import currency | ||
|
||
COMMANDS = {} | ||
|
||
# | ||
# Download wb data | ||
# | ||
|
||
|
||
def download_wb_cli(parser): | ||
log = 'Print log output during download.' | ||
parser.add_argument('--log', help=log, action="store_true") | ||
overwrite = 'Overwrite local files if they exist.' | ||
parser.add_argument('--overwrite', help=overwrite, action="store_true") | ||
|
||
|
||
def download_wb(log=False, overwrite=False, **kwargs): | ||
if log: | ||
logger = logging.getLogger() | ||
logger.setLevel(logging.DEBUG) | ||
|
||
wb = data.WorldBank() | ||
wb.iso_metadata(overwrite=overwrite) | ||
for ind in data.INDICATORS_WB: | ||
wb.query(ind, overwrite=overwrite) | ||
|
||
|
||
COMMANDS['download_wb'] = ( | ||
"""Download national World Bank data to your machine""", | ||
download_wb_cli, | ||
download_wb, | ||
) | ||
|
||
|
||
# | ||
# Currency Exchange | ||
# | ||
|
||
# implement this | ||
|
||
def main(): | ||
descr = """ | ||
Main CLI for salamanca. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
description=descr, | ||
formatter_class=argparse.RawDescriptionHelpFormatter | ||
) | ||
subparsers = parser.add_subparsers(dest='command') | ||
|
||
for cmd in COMMANDS: | ||
cli_help = COMMANDS[cmd][0] | ||
cli_func = COMMANDS[cmd][1] | ||
subparser = subparsers.add_parser(cmd, help=cli_help) | ||
cli_func(subparser) | ||
|
||
args = parser.parse_args() | ||
cmd = args.command | ||
cmd_func = COMMANDS[cmd][2] | ||
cmd_func(**vars(args)) | ||
|
||
if __name__ == '__main__': | ||
main() |