Skip to content

Commit

Permalink
return str instead of Path object
Browse files Browse the repository at this point in the history
  • Loading branch information
alpha-xone committed Jan 16, 2021
1 parent 80032af commit 04dd720
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
21 changes: 10 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-i https://pypi.org/simple
matplotlib>=3.0.2
numpy>=1.15.0
pandas>=1.0.0
pyarrow>=1.0.0
pytz>=2018.7
parse>=1.18.0
tqdm>=4.51.0
beautifulsoup4>=4.9.0
selenium>=3.141.0
requests>=2.25.0
matplotlib >= 3.0.2
numpy >= 1.15.0
pandas >= 1.2.0
pyarrow >= 1.0.1
pytz >= 2020.4
parse >= 1.18.0
tqdm >= 4.51.0
beautifulsoup4 >= 4.9.0
selenium >= 3.141.0
requests >= 2.25.0
2 changes: 1 addition & 1 deletion xone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Frequently used functions for financial data analysis"""

__version__ = '0.1.7b4'
__version__ = '0.1.7b5'

__submodules__ = [
'utils',
Expand Down
37 changes: 19 additions & 18 deletions xone/files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import time
import parse

from typing import List
from pathlib import Path

# Default datetime format:
Expand Down Expand Up @@ -38,7 +40,7 @@ def abspath(cur_file, parent=0) -> Path:
"""
p = Path(cur_file)
cur_path = p.parent if p.is_file() else p
if parent == 0: return cur_path
if parent == 0: return str(cur_path).replace('\\', '/')
return abspath(cur_file=cur_path.parent, parent=parent - 1)


Expand All @@ -56,8 +58,8 @@ def create_folder(path_name: str, is_file=False):

def all_files(
path_name, keyword='', ext='', full_path=True,
has_date=False, date_fmt=DATE_FMT
) -> list:
has_date=False, date_fmt=DATE_FMT,
) -> List(str):
"""
Search all files with criteria
Returned list will be sorted by last modified
Expand Down Expand Up @@ -85,15 +87,17 @@ def all_files(

keyword = f'*{keyword}*' if keyword else '*'
keyword += f'.{ext}' if ext else '.*'
files = list(filter(lambda v: v.name[0] != '~', p.glob(keyword)))

if has_date: files = filter_by_dates(files, date_fmt=date_fmt)
return files if full_path else [f.name for f in files]
dt = parse.compile(date_fmt)
return [
str(f).replace('\\', '/') if full_path else f.name
for f in p.glob(keyword)
if f.is_file() and (f.name[0] != '~') and ((not has_date) or dt.search(f.name))
]


def all_folders(
path_name, keyword='', has_date=False, date_fmt=DATE_FMT
) -> list:
) -> List[str]:
"""
Search all folders with criteria
Returned list will be sorted by last modified
Expand Down Expand Up @@ -122,13 +126,12 @@ def all_folders(
p = Path(path_name)
if not p.is_dir(): return []

folders = list(filter(
lambda v: v.is_dir() and v.name[0] != '~',
p.glob(f'*{keyword}*' if keyword else '*'),
))

if has_date: folders = filter_by_dates(folders, date_fmt=date_fmt)
return folders
dt = parse.compile(date_fmt)
return [
str(f).replace('\\', '/')
for f in p.glob(f'*{keyword}*' if keyword else '*')
if f.is_dir() and (f.name[0] != '~') and ((not has_date) or dt.search(f.name))
]


def sort_by_modified(files_or_folders: list) -> list:
Expand Down Expand Up @@ -161,9 +164,7 @@ def filter_by_dates(files_or_folders: list, date_fmt=DATE_FMT) -> list:
... ])
['t1/dts_2019-01-01', 't2/dts_2019-01-02']
"""
from parse import compile

p = compile(date_fmt)
p = parse.compile(date_fmt)
return list(filter(lambda _: p.search(Path(_).name), files_or_folders))


Expand Down

0 comments on commit 04dd720

Please sign in to comment.