Skip to content

Commit

Permalink
requested change by james incorporated. Headers not working
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-Sibileau committed Jul 9, 2021
1 parent 1a5a32a commit 0270d48
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions transmonee_dashboard/src/transmonee_dashboard/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import requests
from io import StringIO


mapbox_access_token = "pk.eyJ1IjoiamNyYW53ZWxsd2FyZCIsImEiOiJja2NkMW02aXcwYTl5MnFwbjdtdDB0M3oyIn0.zkIzPc4NSjLZvrY-DWrlZg"

sdmx_url = "https://sdmx.data.unicef.org/ws/public/sdmxapi/rest/data/ECARO,TRANSMONEE,1.0/.{}...."
sdmx_url = "https://sdmx.data.unicef.org/ws/public/sdmxapi/rest/data/ECARO,TRANSMONEE,1.0/.{}....?format=csv&startPeriod={}&endPeriod={}"

geocoder = Geocoder(access_token=mapbox_access_token)

Expand Down Expand Up @@ -636,24 +634,18 @@ def geocode_address(address):
"Unit multiplier": str,
}

# api parameters: query format and year limits
api_params = {
"format": "csv",
"startPeriod": str(years[0]),
"endPeriod": str(years[-1]),
}
compress_header = {"Accept-Encoding": "gzip"}

# avoid a loop to query SDMX
try:
response = requests.get(
sdmx_url.format("+".join(inds)), params=api_params, headers=compress_header
sdmx = pd.read_csv(
sdmx_url.format("+".join(inds), years[0], years[-1]),
dtype=col_types,
# great would be to make this http header work!
# storage_options={"Accept-Encoding": "gzip"},
)
except urllib.error.HTTPError as e:
raise e

# bring requests response into pandas
sdmx = pd.read_csv(StringIO(response.text), dtype=col_types)

# no need to create column CODE, just rename indicator
sdmx.rename(columns={"INDICATOR": "CODE"}, inplace=True)
Expand Down

0 comments on commit 0270d48

Please sign in to comment.