-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (30 loc) · 1.21 KB
/
main.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
import logging
import os
import signal
from dotenv import load_dotenv
from hdx.api.configuration import Configuration
from healthsites import get_countries, generate_dataset
from utils import handler
from hdx.data.hdxobject import HDXError
load_dotenv()
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', datefmt='%d/%m/%Y %I:%M:%S %p', level=logging.INFO)
signal.signal(signal.SIGINT, handler) # handle Ctrl+C
def run():
countries = get_countries()
conf = Configuration.create(hdx_site=os.environ['HDX_ENVIRONMENT'], user_agent="Healthsites.io")
for country in countries:
dataset = generate_dataset(country)
dataset.update_from_yaml()
dataset.add_country_location(country)
dataset.set_expected_update_frequency('Every three months')
dataset.add_tag('health facilities')
dataset.set_subnational(True)
logging.info('Uploading files to HDX for %s' % country)
try:
dataset.create_in_hdx()
logging.info('Uploading files to HDX for %s done' % country)
except HDXError:
logging.error('Failed to upload resources for country %s' % country)
pass
if __name__ == "__main__":
run()