Skip to content

Commit

Permalink
Merge pull request #5 from datosgobar/url-handling-#2
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
abenassi committed Nov 30, 2016
2 parents 6159d06 + c5e6fc6 commit c96fc72
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pydatajson/pydatajson.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from __future__ import print_function
from __future__ import with_statement
import os.path
from urlparse import urljoin
from urlparse import urljoin, urlparse
import warnings
import json
import jsonschema
import requests
Expand Down Expand Up @@ -94,10 +95,23 @@ def _deserialize_json(json_path_or_url):
json_path_or_url.
"""
if json_path_or_url.startswith("http"):
parsed_url = urlparse(json_path_or_url)

if parsed_url.scheme in ["http", "https"]:
req = requests.get(json_path_or_url)
json_string = req.content

else:
# En caso de que json_path_or_url parezca ser una URL remota,
# advertirlo
path_start = parsed_url.path.split(".")[0]
if path_start == "www" or path_start.isdigit():
warnings.warn("""
La dirección del archivo JSON ingresada parece una URL, pero no comienza
con 'http' o 'https' así que será tratada como una dirección local. ¿Tal vez
quiso decir 'http://{}'?
""".format(json_path_or_url).encode("utf8"))

with open(json_path_or_url) as json_file:
json_string = json_file.read()

Expand Down

0 comments on commit c96fc72

Please sign in to comment.