import schedule import time import datetime import shutil import redis import urllib.request def query_all_records_by_date_with_type_flow(date: str): try: response = urllib.request.urlopen('localhost/queryallrecordbydatewithtype/?querydate={date}&querytype=flow') html = response.read().decode('utf-8') print(html) except urllib.error.URLError as e: print("Error") def auto_cache_data(): redis_client = redis.Redis(host='localhost', port=6379, db=0) items = ['queryallrecordsbydatewithtype_[DATE]_flow'] today = datetime.date.today() print(today) for item in items: prev_day = today - datetime.timedelta(days=1) str_prev_day = prev_day.strftime('%Y-%m-%d') print(str_prev_day) key = item.replace('[DATE]', str_prev_day) if not redis_client.exists(key): query_all_records_by_date_with_type_flow(str_prev_day) if __name__ == "__main__": auto_cache_data()