def run_once_per_day(f):
    def wrapper(*args, **kwargs):
        try:
            # Phase 1:  Calculate refresh and current date to determine
            #           if whether to download a new copy of the MAC
            #           txt file should be downloaded from the IEEE site.
            #           We do not want to repopulate more than once a day
            # Are we running on Bluemix or not?
            if VCAP_CONFIG:
                nextDate = REDIS_INSTANCE.get("nextDate")
                # Nothing stored for first time this app has been deployed
                if nextDate is None:
                    nextDate = datetime.utcnow()
                else:
                    # Need to convert the cached date from str to datetime
                    nextDate = datetime.strptime(nextDate,
                                                 '%Y-%m-%d %H:%M:%S.%f')
            else:
                # Running local.  First time?
                if not wrapper.has_run:
                    nextDate = datetime.utcnow()
                # We've already populated so let's not populate again
                else:
                    nextDate = datetime.utcnow() + timedelta(seconds=86400)
            # Let's record what datetime it is right now ...
            now = datetime.utcnow()

            # Phase 2:  Test whether the current date is past our 24 hour
            #           refresh date criteria or not.
            print "Evaluating if Now is >= Criteria ..."
            if now >= nextDate:
                print "Refresh criteria has been met"
                # Set a flag so that future local repopulates fall through
                wrapper.has_run = True
                # Test if we are running in Bluemix
                if VCAP_CONFIG:
                    # Persist a refresh date 24 hours in the future
                    REDIS_INSTANCE.set("nextDate", datetime.utcnow()
                                       + timedelta(seconds=86400))
                return f(*args, **kwargs)
            else:
                # Refresh not required, relay a default response
                print "Refresh criteria NOT met"
                data = {
                    'message': 'Whoaa! MacReduce Data is up to date!'
                }
                message = json.dumps(data)
                print message
                resp = Response(message,
                                status=200,
                                mimetype='application/json')
                return resp
        except Exception, e:
            print e
            print traceback.format_exc()
    wrapper.has_run = False
    return wrapper
dataset/ETHPy150Open ibmjstart/bluemix-python-eve-sample/macreduce/routes/home.py/run_once_per_day/original