def show_picture(url):

    local_folder = os.path.join(get_data_path(), "images")
    if not os.path.exists(local_folder):
        try:
            os.mkdir(local_folder)
        except:
            pass
    local_file = os.path.join(local_folder, "temp.jpg")

    # Download picture
    urllib_request.urlretrieve(url, local_file)

    # Show picture
    xbmc.executebuiltin("SlideShow(" + local_folder + ")")
Exemple #2
0
def maybe_download(directory, filename, url):
    """Download filename from url unless it's already in directory.

  Args:
    directory: path to the directory that will be used.
    filename: name of the file to download to (do nothing if it already exists).
    url: URL to download from.

  Returns:
    The path to the downloaded file.
  """
    if not tf.gfile.Exists(directory):
        tf.logging.info("Creating directory %s" % directory)
        os.mkdir(directory)
    filepath = os.path.join(directory, filename)
    if not tf.gfile.Exists(filepath):
        tf.logging.info("Downloading %s to %s" % (url, filepath))
        inprogress_filepath = filepath + ".incomplete"
        inprogress_filepath, _ = urllib.urlretrieve(
            url, inprogress_filepath, reporthook=download_report_hook)
        # Print newline to clear the carriage return from the download progress
        print()
        tf.gfile.Rename(inprogress_filepath, filepath)
        statinfo = os.stat(filepath)
        tf.logging.info("Succesfully downloaded %s, %s bytes." %
                        (filename, statinfo.st_size))
    else:
        tf.logging.info("Not downloading, file already found: %s" % filepath)
    return filepath
def maybe_download(directory, filename, url):
  """Download filename from url unless it's already in directory.

  Args:
    directory: path to the directory that will be used.
    filename: name of the file to download to (do nothing if it already exists).
    url: URL to download from.

  Returns:
    The path to the downloaded file.
  """
  if not tf.gfile.Exists(directory):
    tf.logging.info("Creating directory %s" % directory)
    os.mkdir(directory)
  filepath = os.path.join(directory, filename)
  if not tf.gfile.Exists(filepath):
    tf.logging.info("Downloading %s to %s" % (url, filepath))
    inprogress_filepath = filepath + ".incomplete"
    inprogress_filepath, _ = urllib.urlretrieve(
        url, inprogress_filepath, reporthook=download_report_hook)
    # Print newline to clear the carriage return from the download progress
    print()
    tf.gfile.Rename(inprogress_filepath, filepath)
    statinfo = os.stat(filepath)
    tf.logging.info("Successfully downloaded %s, %s bytes." %
                    (filename, statinfo.st_size))
  else:
    tf.logging.info("Not downloading, file already found: %s" % filepath)
  return filepath
Exemple #4
0
def maybe_download(directory, filename, uri):
    """Download filename from uri unless it's already in directory.

  Copies a remote file to local if that local file does not already exist.  If
  the local file pre-exists this function call, it does not check that the local
  file is a copy of the remote.

  Remote filenames can be filepaths, any URI readable by tensorflow.gfile, or a
  URL.

  Args:
    directory: path to the directory that will be used.
    filename: name of the file to download to (do nothing if it already exists).
    uri: URI to copy (or download) from.

  Returns:
    The path to the downloaded file.
  """
    if not tf.gfile.Exists(directory):
        tf.logging.info("Creating directory %s" % directory)
        tf.gfile.MakeDirs(directory)
    filepath = os.path.join(directory, filename)
    if not tf.gfile.Exists(filepath):
        tf.logging.info("Downloading %s to %s" % (uri, filepath))
        try:
            tf.gfile.Copy(uri, filepath)
        except tf.errors.UnimplementedError:
            if uri.startswith("http"):
                inprogress_filepath = filepath + ".incomplete"
                inprogress_filepath, _ = urllib.urlretrieve(
                    uri, inprogress_filepath, reporthook=download_report_hook)
                # Print newline to clear the carriage return from the download progress
                print()
                tf.gfile.Rename(inprogress_filepath, filepath)
            else:
                raise ValueError("Unrecognized URI: " + filepath)
        statinfo = os.stat(filepath)
        tf.logging.info("Successfully downloaded %s, %s bytes." %
                        (filename, statinfo.st_size))
    else:
        tf.logging.info("Not downloading, file already found: %s" % filepath)
    return filepath
def maybe_download(directory, filename, uri):
  """Download filename from uri unless it's already in directory.

  Copies a remote file to local if that local file does not already exist.  If
  the local file pre-exists this function call, it does not check that the local
  file is a copy of the remote.

  Remote filenames can be filepaths, any URI readable by tensorflow.gfile, or a
  URL.

  Args:
    directory: path to the directory that will be used.
    filename: name of the file to download to (do nothing if it already exists).
    uri: URI to copy (or download) from.

  Returns:
    The path to the downloaded file.
  """
  if not tf.gfile.Exists(directory):
    tf.logging.info("Creating directory %s" % directory)
    tf.gfile.MakeDirs(directory)
  filepath = os.path.join(directory, filename)
  if not tf.gfile.Exists(filepath):
    tf.logging.info("Downloading %s to %s" % (uri, filepath))
    try:
      tf.gfile.Copy(uri, filepath)
    except tf.errors.UnimplementedError:
      if uri.startswith("http"):
        inprogress_filepath = filepath + ".incomplete"
        inprogress_filepath, _ = urllib.urlretrieve(
            uri, inprogress_filepath, reporthook=download_report_hook)
        # Print newline to clear the carriage return from the download progress
        print()
        tf.gfile.Rename(inprogress_filepath, filepath)
      else:
        raise ValueError("Unrecognized URI: " + filepath)
    statinfo = os.stat(filepath)
    tf.logging.info("Successfully downloaded %s, %s bytes." %
                    (filename, statinfo.st_size))
  else:
    tf.logging.info("Not downloading, file already found: %s" % filepath)
  return filepath