import os

from invoke import task

from .constants import COUNTRY_DIR
from .utils import load_module

@task(help={
    'state':'Two-letter state-abbreviation, e.g. NY',
    'year': '4-digit election year',
    'elecdate': 'Fetch files for a specific date YYYY-MM-DD'
})
def fetch(state, year='', elecdate=''):
    """
    Scrape raw data files, generate standardized names, 
    and store in local file cache.

    State is required. Optionally provide 'year' 
    or 'elecdate' to limit files that are fetched.
    """
    state_mod = load_module(state, 'fetch')
    state_dir = os.path.join(COUNTRY_DIR, state) 
    fetcher = state_mod.fetch.FetchResults()
    fetcher.run(year)

@@ -172,100 +172,79 @@
    '
-year': '4-digit election year',%0A    'elecdate': 'Fetch files for a specific date YYYY-MM-DD'
+datefilter': 'Any portion of a YYYYMMDD date, e.g. YYYY, YYYYMM, etc.',
 %0A%7D)%0A
@@ -264,25 +264,18 @@
 te, 
-year='', elecda
+datefil
 te
+r
 ='')
@@ -424,32 +424,24 @@
 de '
-year' %0A    or 'elecdate'
+datefilter' %0A   
  to 
@@ -637,10 +637,16 @@
 run(
-yea
+datefilte
 r)%0A

update fetch task to use generic datefilter