From 4eca7085854210ed5a9efa644bc359051feda861 Mon Sep 17 00:00:00 2001 From: Mario Graff Date: Mon, 4 Aug 2025 12:12:23 -0500 Subject: [PATCH 1/2] return path in download --- encexp/__init__.py | 2 +- encexp/download.py | 5 ++++- encexp/tests/test_download.py | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/encexp/__init__.py b/encexp/__init__.py index 8df4d85..0499652 100644 --- a/encexp/__init__.py +++ b/encexp/__init__.py @@ -17,4 +17,4 @@ if not '-m' in sys.argv: from encexp.text_repr import EncExpT, SeqTM, TextModel -__version__ = "0.1.7" +__version__ = "0.1.8" diff --git a/encexp/download.py b/encexp/download.py index 893ed95..177a2cd 100644 --- a/encexp/download.py +++ b/encexp/download.py @@ -19,7 +19,8 @@ def download(identifier: str, first: bool=True, base_url: str=EncExp_URL, - outputdir: str=MODELS): + outputdir: str=MODELS, + return_path: bool=False): """download""" if not isdir(outputdir): os.mkdir(outputdir) @@ -32,6 +33,8 @@ def download(identifier: str, first: bool=True, except Exception: os.unlink(output) Download(base_url + f'/{identifier}.json.gz', output) + if return_path: + return output if first: return next(tweet_iterator(output)) return tweet_iterator(output) diff --git a/encexp/tests/test_download.py b/encexp/tests/test_download.py index 9607cb2..fb43b46 100644 --- a/encexp/tests/test_download.py +++ b/encexp/tests/test_download.py @@ -15,11 +15,18 @@ from os.path import isfile import os import numpy as np -from encexp.download import download_TextModel +from encexp.download import download_TextModel, download def test_download_TextModel(): """Test download TextModel""" from encexp import TextModel tm = TextModel(lang='es') - download_TextModel(tm.identifier) \ No newline at end of file + download_TextModel(tm.identifier) + + +def test_download_path(): + """Test download path""" + + path = download('es_info', return_path=True) + assert isfile(path) \ No newline at end of file From ff7c91acc2ca382033b0d78075090bca7e2dfdf6 Mon Sep 17 00:00:00 2001 From: Mario Graff Date: Mon, 4 Aug 2025 12:18:16 -0500 Subject: [PATCH 2/2] bug download --- encexp/download.py | 2 ++ encexp/tests/test_download.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/encexp/download.py b/encexp/download.py index 177a2cd..13d951e 100644 --- a/encexp/download.py +++ b/encexp/download.py @@ -26,6 +26,8 @@ def download(identifier: str, first: bool=True, os.mkdir(outputdir) output = join(outputdir, f'{identifier}.json.gz') if isfile(output): + if return_path: + return output try: if first: return next(tweet_iterator(output)) diff --git a/encexp/tests/test_download.py b/encexp/tests/test_download.py index fb43b46..4dafabe 100644 --- a/encexp/tests/test_download.py +++ b/encexp/tests/test_download.py @@ -28,5 +28,7 @@ def test_download_TextModel(): def test_download_path(): """Test download path""" + path = download('es_info', return_path=True) + assert isfile(path) path = download('es_info', return_path=True) assert isfile(path) \ No newline at end of file