From 2a5edd42238f06e928b5bc54db33b8547951ab17 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 6 Jun 2016 22:27:46 -0400 Subject: [PATCH] Removed downloader.sh --- bashplotlib/histogram.py | 27 +++++++++++++++++++++++++-- bin/texas | 4 +--- examples/downloaddata.sh | 14 -------------- examples/sample.sh | 5 +++-- setup.py | 2 ++ 5 files changed, 31 insertions(+), 21 deletions(-) delete mode 100755 examples/downloaddata.sh diff --git a/bashplotlib/histogram.py b/bashplotlib/histogram.py index 43b7dd3..47617a4 100644 --- a/bashplotlib/histogram.py +++ b/bashplotlib/histogram.py @@ -12,10 +12,23 @@ import sys import math import optparse +import requests from os.path import dirname +from multiprocessing import Pool + from .utils.helpers import * from .utils.commandhelp import hist +sample_files = [('exp.txt', 'yuxlaj8okcjta9t', ''), + ('lower48.txt', 'cbf5skx34grlwy6', ''), + ('x_test.txt', 'gsu2y9vqnx5ps5i', ''), + ('y_test.txt', 'mlt4gfqr6n24kxj', ''), + ('texas.txt', 'gsu2y9vqnx5ps5i', ''), + ('million.txt', 'jjeubxlxuqkzkeq/5W6zkUZXww/', 'h')] + +download_base = 'https://dl.dropbox.com/s{}/{}/{}?dl=1' +download_dir = os.path.join(os.environ['HOME'], 'bashplotlib/examples/data') + def calc_bins(n, min_val, max_val, h=None, binwidth=None): """ @@ -46,12 +59,22 @@ def read_numbers(numbers): yield float(number.strip()) +def sample_data_downloader(filename, fileid, prefix): + req = requests.get(download_base.format(prefix, fileid, filename)) + filepath = os.path.join(download_dir, filename) + with open(filepath, 'w') as f: + f.write(req.text) + + def run_demo(): """ Run a demonstration """ - module_dir = dirname(dirname(os.path.realpath(__file__))) - demo_file = os.path.join(module_dir, 'examples/data/exp.txt') + if not os.path.exists(download_dir): + os.mkdir(download_dir) + with Pool() as pool: + pool.starmap(sample_data_downloader, sample_files) + demo_file = os.path.join(download_dir, 'exp.txt') if not os.path.isfile(demo_file): sys.stderr.write("demo input file not found!\n") diff --git a/bin/texas b/bin/texas index d62bc78..73a8e4a 100755 --- a/bin/texas +++ b/bin/texas @@ -3,7 +3,5 @@ from __future__ import print_function import os -_ROOT = os.path.abspath(os.path.dirname(__file__)) - -texas = os.path.join(_ROOT, "../bashplotlib", "data", "texas.txt") +texas = os.path.join(os.environ["HOME"], "bashplotlib/examples/data/texas.txt") print(open(texas).read().strip()) diff --git a/examples/downloaddata.sh b/examples/downloaddata.sh deleted file mode 100755 index ba2298f..0000000 --- a/examples/downloaddata.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -dir=$(dirname "$0") - -if [ ! -d "${dir}data" ]; then - mkdir "${dir}/data" -fi - -curl -L 'https://dl.dropbox.com/sh/jjeubxlxuqkzkeq/5W6zkUZXww/million.txt?dl=1' > "${dir}/data/million.txt" -curl -L 'https://dl.dropbox.com/s/yuxlaj8okcjta9t/exp.txt?dl=1' > "${dir}/data/exp.txt" -curl -L 'https://dl.dropbox.com/s/cbf5skx34grlwy6/lower48.txt?dl=1' > "${dir}/data/lower48.txt" -curl -L 'https://dl.dropbox.com/s/gsu2y9vqnx5ps5i/texas.txt?dl=1' > "${dir}/data/texas.txt" -curl -L 'https://dl.dropbox.com/s/4zws1nbamorcy9z/x_test.txt?dl=1' > "${dir}/data/x_test.txt" -curl -L 'https://dl.dropbox.com/s/mlt4gfqr6n24kxj/y_test.txt?dl=1' > "${dir}/data/y_test.txt" diff --git a/examples/sample.sh b/examples/sample.sh index 02985ed..6356c76 100755 --- a/examples/sample.sh +++ b/examples/sample.sh @@ -3,8 +3,9 @@ dir=$(dirname "$0") if [ ! -d "${dir}/data" ]; then - echo 'downloading data' - "${dir}/downloaddata.sh" + echo 'Sample data is needed' + echo 'Run "hist --demo" to download' + exit 1 fi echo 'plotting coordinates' diff --git a/setup.py b/setup.py index da6e1af..5094969 100644 --- a/setup.py +++ b/setup.py @@ -26,5 +26,7 @@ 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', ], + install_requires={'requests':'examples'}, + dependency_links=['https://github.com/kennethreitz/requests'], )