From d51a4cb2542dcd223624b4ac05292e6e80a780f9 Mon Sep 17 00:00:00 2001 From: PyMap Date: Tue, 29 Sep 2020 16:50:57 -0300 Subject: [PATCH] Synthpop-planning issue#36 Tidy up hardcoded URLs --- synthpop/census_helpers.py | 8 ++------ synthpop/config.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 synthpop/config.py diff --git a/synthpop/census_helpers.py b/synthpop/census_helpers.py index 78331ef..344de28 100644 --- a/synthpop/census_helpers.py +++ b/synthpop/census_helpers.py @@ -3,6 +3,7 @@ import numpy as np import us import requests +from .config import synthpop_config # code to retry when census api fails sess = requests.Session() @@ -16,12 +17,7 @@ class Census: def __init__(self, key, acsyear=2016): self.c = census.Census(key, session=sess) - - if acsyear >= 2018: - storage = "https://storage.googleapis.com/synthpop-public/PUMS2018/pums_2018_acs5/" - else: - storage = "https://s3-us-west-1.amazonaws.com/synthpop-data2/" - self.base_url = storage + self.base_url = synthpop_config(acsyear).pums_storage() self.acsyear_files = acsyear self.pums_relationship_file_url = self.base_url + "tract10_to_puma.csv" self.pums_relationship_df = None diff --git a/synthpop/config.py b/synthpop/config.py new file mode 100644 index 0000000..221a12a --- /dev/null +++ b/synthpop/config.py @@ -0,0 +1,14 @@ +class synthpop_config: + + def __init__(self, acsyear=2013): + self.acsyear = acsyear + + def pums_storage(self): + if self.acsyear >= 2018: + storage = "https://storage.googleapis.com/synthpop-public/PUMS2018/pums_2018_acs5/" + else: + storage = "https://s3-us-west-1.amazonaws.com/synthpop-data2/" + return storage + + def __call__(self): + return self.pums_storage()