Skip to content

Commit 2a5edd4

Browse files
committed
Removed downloader.sh
1 parent 414aaa3 commit 2a5edd4

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

bashplotlib/histogram.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@
1212
import sys
1313
import math
1414
import optparse
15+
import requests
1516
from os.path import dirname
17+
from multiprocessing import Pool
18+
1619
from .utils.helpers import *
1720
from .utils.commandhelp import hist
1821

22+
sample_files = [('exp.txt', 'yuxlaj8okcjta9t', ''),
23+
('lower48.txt', 'cbf5skx34grlwy6', ''),
24+
('x_test.txt', 'gsu2y9vqnx5ps5i', ''),
25+
('y_test.txt', 'mlt4gfqr6n24kxj', ''),
26+
('texas.txt', 'gsu2y9vqnx5ps5i', ''),
27+
('million.txt', 'jjeubxlxuqkzkeq/5W6zkUZXww/', 'h')]
28+
29+
download_base = 'https://dl.dropbox.com/s{}/{}/{}?dl=1'
30+
download_dir = os.path.join(os.environ['HOME'], 'bashplotlib/examples/data')
31+
1932

2033
def calc_bins(n, min_val, max_val, h=None, binwidth=None):
2134
"""
@@ -46,12 +59,22 @@ def read_numbers(numbers):
4659
yield float(number.strip())
4760

4861

62+
def sample_data_downloader(filename, fileid, prefix):
63+
req = requests.get(download_base.format(prefix, fileid, filename))
64+
filepath = os.path.join(download_dir, filename)
65+
with open(filepath, 'w') as f:
66+
f.write(req.text)
67+
68+
4969
def run_demo():
5070
"""
5171
Run a demonstration
5272
"""
53-
module_dir = dirname(dirname(os.path.realpath(__file__)))
54-
demo_file = os.path.join(module_dir, 'examples/data/exp.txt')
73+
if not os.path.exists(download_dir):
74+
os.mkdir(download_dir)
75+
with Pool() as pool:
76+
pool.starmap(sample_data_downloader, sample_files)
77+
demo_file = os.path.join(download_dir, 'exp.txt')
5578

5679
if not os.path.isfile(demo_file):
5780
sys.stderr.write("demo input file not found!\n")

bin/texas

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
from __future__ import print_function
44
import os
55

6-
_ROOT = os.path.abspath(os.path.dirname(__file__))
7-
8-
texas = os.path.join(_ROOT, "../bashplotlib", "data", "texas.txt")
6+
texas = os.path.join(os.environ["HOME"], "bashplotlib/examples/data/texas.txt")
97
print(open(texas).read().strip())

examples/downloaddata.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/sample.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
dir=$(dirname "$0")
44

55
if [ ! -d "${dir}/data" ]; then
6-
echo 'downloading data'
7-
"${dir}/downloaddata.sh"
6+
echo 'Sample data is needed'
7+
echo 'Run "hist --demo" to download'
8+
exit 1
89
fi
910

1011
echo 'plotting coordinates'

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@
2626
'Programming Language :: Python :: 2.7',
2727
'Programming Language :: Python :: 3',
2828
],
29+
install_requires={'requests':'examples'},
30+
dependency_links=['https://github.com/kennethreitz/requests'],
2931
)
3032

0 commit comments

Comments
 (0)