-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added scheduling and more intelligent handling of fresh data
- Loading branch information
dhuser
committed
Apr 24, 2018
1 parent
7963c16
commit db12789
Showing
12 changed files
with
187 additions
and
120 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 |
---|---|---|
@@ -1,27 +1,21 @@ | ||
[[source]] | ||
|
||
url = "https://pypi.python.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
|
||
[dev-packages] | ||
|
||
pytest = "*" | ||
pytest-coverage = "*" | ||
sphinx = "*" | ||
sphinx-rtd-theme = "*" | ||
|
||
|
||
[packages] | ||
|
||
requests = "*" | ||
records = "*" | ||
logzero = "*" | ||
alembic = "*" | ||
colorama = {markers = "sys_platform == 'win32'"} | ||
|
||
apscheduler = "*" | ||
|
||
[requires] | ||
|
||
python_version = "3.5" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,66 +1,5 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import sys | ||
|
||
from logzero import logger | ||
|
||
from .core.config import setup as setup_with_config | ||
from .core.helpers import read_csv, parse_args | ||
from .core.verbalautopsy import Event, verbal_autopsy_factory | ||
from .core.exceptions.base import SmartVADHIS2Exception | ||
from .core.exceptions.errors import ImportException, DuplicateEventImportError | ||
|
||
|
||
def smartva_to_dhis2(db, dhis, smartva_file): | ||
if smartva_file: | ||
for i, record in enumerate(read_csv(smartva_file), 1): | ||
logger.info("{0} ROW NUMBER: {1} {0}".format('----------', i)) | ||
va, exceptions, warnings = verbal_autopsy_factory(record) | ||
if warnings: | ||
[logger.warn("{} for record {}".format(warning, record)) for warning in warnings] | ||
if not exceptions: | ||
event = Event(va) | ||
try: | ||
dhis.is_duplicate(va.sid) | ||
except DuplicateEventImportError as e: | ||
logger.exception(e) | ||
db.write_errors(va, e) | ||
else: | ||
try: | ||
dhis.post_event(event.payload) | ||
except ImportException as e: | ||
logger.exception("{}\nfor payload {}".format(e, event.payload)) | ||
db.write_errors(va, [e]) | ||
else: | ||
[logger.exception("{} for record {}".format(exception, record)) for exception in exceptions] | ||
db.write_errors(va, exceptions) | ||
|
||
|
||
def run(arguments): | ||
dhis, briefcase, smartva, db = setup_with_config() | ||
|
||
smartva_file = None | ||
if arguments.briefcase_file: | ||
smartva_file = smartva.run(arguments.briefcase_file, manual=True) | ||
else: | ||
briefcase_file = briefcase.download_briefcases(arguments.all) | ||
if briefcase_file: | ||
smartva_file = smartva.run(briefcase_file) | ||
else: | ||
logger.warning("No new briefcases downloaded") | ||
|
||
smartva_to_dhis2(db, dhis, smartva_file) | ||
|
||
|
||
def main(): | ||
try: | ||
args = parse_args(sys.argv[1:]) | ||
run(args) | ||
except KeyboardInterrupt: | ||
logger.warning("Aborted!") | ||
except Exception as e: | ||
raise SmartVADHIS2Exception(e) | ||
from .run import launch | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
launch() |
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
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
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
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
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
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
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
Oops, something went wrong.