Skip to content

Commit

Permalink
Synthpop-planning issue#36
Browse files Browse the repository at this point in the history
Tidy up hardcoded URLs
  • Loading branch information
PyMap committed Sep 29, 2020
1 parent 52b821a commit d51a4cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions synthpop/census_helpers.py
Expand Up @@ -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()
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions 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()

0 comments on commit d51a4cb

Please sign in to comment.