Skip to content

Commit

Permalink
fix: Optionally unzip.
Browse files Browse the repository at this point in the history
  • Loading branch information
brookemckim committed Sep 30, 2024
1 parent 1eb12d3 commit ac77935
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ lxml
requests
six
boto3
pyyaml
pyyaml
9 changes: 8 additions & 1 deletion scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import json
import locale
import gzip
import ec2
import os
import requests
Expand Down Expand Up @@ -252,7 +253,13 @@ def add_pricing_info(instances):


def fetch_data(url):
content = urllib2.urlopen(url).read().decode()
response = urllib2.urlopen(url).read()

try:
content = response.decode()
except UnicodeDecodeError:
content = gzip.decompress(response).decode()

try:
pricing = json.loads(content)
except ValueError:
Expand Down

0 comments on commit ac77935

Please sign in to comment.