From 790db21a8eed65d77d784de69a8d6a10f4e45701 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Sat, 22 Mar 2025 08:29:07 +0800 Subject: [PATCH] Update auto_cache --- auto_cache.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/auto_cache.py b/auto_cache.py index 65a9a4d..5d0b968 100644 --- a/auto_cache.py +++ b/auto_cache.py @@ -5,16 +5,51 @@ import shutil import redis import urllib.request -def query_all_records_by_date_with_type_link(date: str): +def query_all_records_by_date_with_type(date: str): try: + response = urllib.request.urlopen(f'http://localhost/queryallrecordsbydatewithtype/?querydate={date}&querytype=node') + html = response.read().decode('utf-8') + print(html) + response = urllib.request.urlopen(f'http://localhost/queryallrecordsbydatewithtype/?querydate={date}&querytype=link') html = response.read().decode('utf-8') print(html) except urllib.error.URLError as e: print("Error") -def auto_cache_data(): +def queryallrecordsbydateproperty(date: str): + try: + response = urllib.request.urlopen(f'http://localhost/queryallrecordsbydateproperty/?querydate={date}&querytype=node&property=head') + html = response.read().decode('utf-8') + print(html) + response = urllib.request.urlopen(f'http://localhost/queryallrecordsbydateproperty/?querydate={date}&querytype=link&property=flow') + html = response.read().decode('utf-8') + print(html) + + except urllib.error.URLError as e: + print("Error") + +def queryallscadarecordsbydate(date: str): + try: + response = urllib.request.urlopen(f'http://localhost/queryallscadarecordsbydate/?querydate={date}') + html = response.read().decode('utf-8') + print(html) + except urllib.error.URLError as e: + print("Error") + +def queryallschemeallrecords(date: str): + try: + response = urllib.request.urlopen(f'http://localhost/queryallschemeallrecords/?schemetype=burst_Analysis&schemename=testSchema&querydate={date}') + 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]_link'] @@ -29,10 +64,23 @@ def auto_cache_data(): if not redis_client.exists(key): query_all_records_by_date_with_type_link(str_prev_day) + """ + today = datetime.date.today() + prev_day = today - datetime.timedelta(days=1) + str_prev_day = prev_day.strftime('%Y-%m-%d') + print(str_prev_day) + + query_all_records_by_date_with_type(str_prev_day) + queryallrecordsbydateproperty(str_prev_day) + queryallscadarecordsbydate(str_prev_day) + queryallschemeallrecords(str_prev_day) if __name__ == "__main__": + auto_cache_data() + schedule.every().day.at("03:00").do(auto_cache_data) while True: schedule.run_pending() time.sleep(1) +