|
12 | 12 | import sys |
13 | 13 | import math |
14 | 14 | import optparse |
| 15 | +import requests |
15 | 16 | from os.path import dirname |
| 17 | +from multiprocessing import Pool |
| 18 | + |
16 | 19 | from .utils.helpers import * |
17 | 20 | from .utils.commandhelp import hist |
18 | 21 |
|
| 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 | + |
19 | 32 |
|
20 | 33 | def calc_bins(n, min_val, max_val, h=None, binwidth=None): |
21 | 34 | """ |
@@ -46,12 +59,22 @@ def read_numbers(numbers): |
46 | 59 | yield float(number.strip()) |
47 | 60 |
|
48 | 61 |
|
| 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 | + |
49 | 69 | def run_demo(): |
50 | 70 | """ |
51 | 71 | Run a demonstration |
52 | 72 | """ |
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') |
55 | 78 |
|
56 | 79 | if not os.path.isfile(demo_file): |
57 | 80 | sys.stderr.write("demo input file not found!\n") |
|
0 commit comments