Skip to content

Commit

Permalink
fixing cache bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperdff committed Aug 28, 2021
1 parent 86be063 commit 499e595
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 18 additions & 5 deletions nfl_data_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy
import datetime
import appdirs
import os

# module level doc string
__doc__ = """
Expand Down Expand Up @@ -71,17 +72,23 @@ def import_pbp_data(years, columns=None, downcast=True, cache=False, alt_path=No
appauthor = 'cooper_dff'

plays = pandas.DataFrame()

if alt_path is None:
dpath = appdirs.user_cache_dir(appname, appauthor) + '\\pbp'
else:
dpath = alt_path

# read in pbp data
for year in years:

for folder in [dpath + '\\' + x + '\\' for x in os.listdir(dpath) if ('season='+str(year)) in x]:
for file in os.listdir(folder):
if file.endswith(".parquet"):
fpath = os.path.join(folder, file)

# define path based on cache and alt_path variables
if cache is True:
if alt_path is None:
alt_path = ''
path = appdirs.user_cache_dir(appname, appauthor) + '\\pbp'
else:
url = alt_path
path = fpath
else:
path = url1 + str(year) + url2

Expand Down Expand Up @@ -146,6 +153,12 @@ def cache_pbp(years, downcast=True, alt_path=None):
path = alt_path
else:
path = appdirs.user_cache_dir(appname, appauthor) + '\\pbp'

# delete seasons to be replaced
for folder in [path + '\\' + x + '\\' for x in os.listdir(path) for y in years if ('season='+str(y)) in x]:
for file in os.listdir(folder):
if file.endswith(".parquet"):
os.remove(os.path.join(folder, file))

# read in pbp data
for year in years:
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = '[email protected]'
AUTHOR = 'cooperdff'
REQUIRES_PYTHON = '>=3.5.0'
VERSION = '0.2.1'
VERSION = '0.2.3'


# What packages are required for this module to be executed?
Expand All @@ -29,7 +29,8 @@
'fastparquet>0.5',
'python-snappy>0.5',
'snappy>1',
'appdirs>1'
'appdirs>1',
'os'
]

# What packages are optional?
Expand Down

0 comments on commit 499e595

Please sign in to comment.