Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions rbiparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_sheet_urls(url):
"""Scrapes the RBI page and gets the list of .xlsx sheets."""
r = requests.get(url)
if r.status_code != 200:
raise Exception("Invalid response from", url)
raise Exception("Invalid response from %s" % url)

# Extract the urls.
s = soup(r.content, "lxml")
Expand All @@ -90,7 +90,7 @@ def convert_xlsx_to_csv(src, target, headers):
try:
sheet = xlrd.open_workbook(src).sheet_by_index(0)
except Exception as e:
raise Exception("Can't open sheet.", str(e))
raise Exception("Can't open sheet. : %s" % str(e))

with open(target, "wb") as cf:
writer = csv.writer(cf, quoting=csv.QUOTE_ALL)
Expand All @@ -112,7 +112,7 @@ def convert_xlsx_to_csv(src, target, headers):

writer.writerow(vals)
except Exception as e:
raise Exception("Can't convert sheet.", str(e))
raise Exception("Can't convert sheet. : %s" % str(e))


def url_to_file(url):
Expand All @@ -135,7 +135,7 @@ def save_etags(etags, fname):
with open(fname, "w") as f:
f.write(json.dumps(etags, indent=4))
except Exception as e:
raise Exception("Could not write to " + fname + ": " + str(e))
raise Exception("Could not write to %s : %s" % (fname, str(e)))


def get_url_headers(url):
Expand All @@ -144,7 +144,7 @@ def get_url_headers(url):
r = requests.head(url)
return r.headers
except Exception as e:
raise Exception("Can't reach", url, ": ", str(e))
raise Exception("Can't reach, url: %s : %s" % (url, str(e)))


def download(url, target):
Expand All @@ -153,15 +153,15 @@ def download(url, target):
r = requests.get(url, stream=True)
r.raw.decode_content = True
except Exception as e:
raise Exception("Can't download", url, ": ", str(e))
raise Exception("Can't download, url: %s : %s" % (url, str(e)))

try:
with open(target, "wb") as f:
for chunk in r.iter_content(chunk_size=10000):
if chunk:
f.write(chunk)
except Exception as e:
raise Exception("Can't write ", target, ": ", str(e))
raise Exception("Can't write, target: %s : %s" % (target, str(e)))

return {
"etag": r.headers.get("etag", ""),
Expand Down